[PATCH] D131791: [llvm] Fix assertion when stat fails in remove_directories
Ben Langmuir via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 12 11:35:18 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG79f34ae7fe92: [llvm] Fix assertion when stat fails in remove_directories (authored by benlangmuir).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131791/new/
https://reviews.llvm.org/D131791
Files:
llvm/lib/Support/Unix/Path.inc
llvm/unittests/Support/Path.cpp
Index: llvm/unittests/Support/Path.cpp
===================================================================
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -816,6 +816,28 @@
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
Index: llvm/lib/Support/Unix/Path.inc
===================================================================
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -1273,19 +1273,20 @@
while (Begin != End) {
auto &Item = *Begin;
ErrorOr<basic_file_status> st = Item.status();
- if (!st && !IgnoreErrors)
- return st.getError();
+ if (st) {
+ if (is_directory(*st)) {
+ EC = remove_directories_impl(Item, IgnoreErrors);
+ if (EC && !IgnoreErrors)
+ return EC;
+ }
- if (is_directory(*st)) {
- EC = remove_directories_impl(Item, IgnoreErrors);
+ EC = fs::remove(Item.path(), true);
if (EC && !IgnoreErrors)
return EC;
+ } else if (!IgnoreErrors) {
+ return st.getError();
}
- EC = fs::remove(Item.path(), true);
- if (EC && !IgnoreErrors)
- return EC;
-
Begin.increment(EC);
if (EC && !IgnoreErrors)
return EC;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131791.452247.patch
Type: text/x-patch
Size: 2230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220812/ad2707a1/attachment.bin>
More information about the llvm-commits
mailing list