[sanitizer] Check if directory exists before trying to create
authorTeresa Johnson <tejohnson@google.com>
Thu, 10 Feb 2022 23:42:38 +0000 (15:42 -0800)
committerTeresa Johnson <tejohnson@google.com>
Sun, 13 Feb 2022 14:59:32 +0000 (06:59 -0800)
commit634da7a1c61ee8c173e90a841eb1f4ea03caa20b
tree0fac9e32f4f33f4923424c3092a21f17ce5b232d
parent0e4ecfaf5a29ca146cbcc08ed38e7b7565d4580f
[sanitizer] Check if directory exists before trying to create

Add a DirExists mechanism, modeled after FileExists. Use it to guard
creation of the report path directory.

This should avoid failures running the sanitizer in a sandbox where the
file creation attempt causes hard failures, even for an existing
directory. Problem reported on D109794 for ChromeOS in sandbox
(https://issuetracker.google.com/209296420).

Differential Revision: https://reviews.llvm.org/D119495
compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
compiler-rt/lib/sanitizer_common/sanitizer_file.h
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cpp
compiler-rt/test/asan/TestCases/log-path_test.cpp
compiler-rt/test/memprof/TestCases/log_path_test.cpp
compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_path_test.cpp