diff options
author | Ben Langmuir <blangmuir@apple.com> | 2022-08-12 10:16:56 -0700 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2022-08-12 11:32:04 -0700 |
commit | 79f34ae7fe926c907c2e68b22fc15428f2e4be4e (patch) | |
tree | 92fa69f6d85d601edf35241d815dbded3f404e3a /llvm/unittests/Support/Path.cpp | |
parent | 7ddfb4dfeb1c52fa0714f1a0784899d7ccd23900 (diff) | |
download | llvm-79f34ae7fe926c907c2e68b22fc15428f2e4be4e.zip llvm-79f34ae7fe926c907c2e68b22fc15428f2e4be4e.tar.gz llvm-79f34ae7fe926c907c2e68b22fc15428f2e4be4e.tar.bz2 |
[llvm] Fix assertion when stat fails in remove_directories
We were dereferencing an empty Optional if IgnoreErrors was true and the
stat failed.
rdar://60887887
Differential Revision: https://reviews.llvm.org/D131791
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index 6f00227..08460a9 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -816,6 +816,28 @@ TEST_F(FileSystemTest, RealPathNoReadPerm) { ASSERT_NO_ERROR(fs::remove_directories(Twine(TestDirectory) + "/noreadperm")); } +TEST_F(FileSystemTest, RemoveDirectoriesNoExePerm) { + SmallString<64> Expanded; + + ASSERT_NO_ERROR( + fs::create_directories(Twine(TestDirectory) + "/noexeperm/foo")); + ASSERT_TRUE(fs::exists(Twine(TestDirectory) + "/noexeperm/foo")); + + fs::setPermissions(Twine(TestDirectory) + "/noexeperm", + fs::all_read | fs::all_write); + + ASSERT_NO_ERROR(fs::remove_directories(Twine(TestDirectory) + "/noexeperm", + /*IgnoreErrors=*/true)); + ASSERT_TRUE(fs::exists(Twine(TestDirectory) + "/noexeperm")); + ASSERT_EQ(fs::remove_directories(Twine(TestDirectory) + "/noexeperm", + /*IgnoreErrors=*/false), + errc::permission_denied); + + fs::setPermissions(Twine(TestDirectory) + "/noexeperm", fs::all_perms); + + ASSERT_NO_ERROR(fs::remove_directories(Twine(TestDirectory) + "/noexeperm", + /*IgnoreErrors=*/false)); +} #endif |