[Lldb-commits] [lldb] 2c1108f - FileSystem::EnumerateDirectory should skip entries w/o Status, not halt
Jason Molenda via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 26 17:53:46 PDT 2023
Author: Jason Molenda
Date: 2023-06-26T17:46:53-07:00
New Revision: 2c1108f44342019a67ce55bb98e2a05b57a70b9a
URL: https://github.com/llvm/llvm-project/commit/2c1108f44342019a67ce55bb98e2a05b57a70b9a
DIFF: https://github.com/llvm/llvm-project/commit/2c1108f44342019a67ce55bb98e2a05b57a70b9a.diff
LOG: FileSystem::EnumerateDirectory should skip entries w/o Status, not halt
EnumerateDirectory gets the vfs::Status of each directory entry to
decide how to process it. If it is unable to get the Status for
a directory entry, it will currently halt the directory iteration
entirely. It should only skip this entry.
Differential Revision: https://reviews.llvm.org/D153822
rdar://110861210
Added:
Modified:
lldb/source/Host/common/FileSystem.cpp
lldb/unittests/Host/FileSystemTest.cpp
Removed:
################################################################################
diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp
index 96ff1bf13bd7d..1fe4e8fdd500e 100644
--- a/lldb/source/Host/common/FileSystem.cpp
+++ b/lldb/source/Host/common/FileSystem.cpp
@@ -192,7 +192,7 @@ void FileSystem::EnumerateDirectory(Twine path, bool find_directories,
const auto &Item = *Iter;
ErrorOr<vfs::Status> Status = m_fs->status(Item.path());
if (!Status)
- break;
+ continue;
if (!find_files && Status->isRegularFile())
continue;
if (!find_directories && Status->isDirectory())
diff --git a/lldb/unittests/Host/FileSystemTest.cpp b/lldb/unittests/Host/FileSystemTest.cpp
index facb7ae5f1768..4ed9beff4d303 100644
--- a/lldb/unittests/Host/FileSystemTest.cpp
+++ b/lldb/unittests/Host/FileSystemTest.cpp
@@ -51,6 +51,11 @@ class DummyFileSystem : public vfs::FileSystem {
FilesAndDirs.find(Path.str());
if (I == FilesAndDirs.end())
return make_error_code(llvm::errc::no_such_file_or_directory);
+ // Simulate a broken symlink, where it points to a file/dir that
+ // does not exist.
+ if (I->second.isSymlink() &&
+ I->second.getPermissions() == sys::fs::perms::no_perms)
+ return std::error_code(ENOENT, std::generic_category());
return I->second;
}
ErrorOr<std::unique_ptr<vfs::File>>
@@ -152,6 +157,13 @@ class DummyFileSystem : public vfs::FileSystem {
sys::fs::file_type::symlink_file, sys::fs::all_all);
addEntry(Path, S);
}
+
+ void addBrokenSymlink(StringRef Path) {
+ vfs::Status S(Path, UniqueID(FSID, FileID++),
+ std::chrono::system_clock::now(), 0, 0, 0,
+ sys::fs::file_type::symlink_file, sys::fs::no_perms);
+ addEntry(Path, S);
+ }
};
} // namespace
@@ -178,6 +190,7 @@ static IntrusiveRefCntPtr<DummyFileSystem> GetSimpleDummyFS() {
D->addRegularFile("/foo");
D->addDirectory("/bar");
D->addSymlink("/baz");
+ D->addBrokenSymlink("/lux");
D->addRegularFile("/qux", ~sys::fs::perms::all_read);
D->setCurrentWorkingDirectory("/");
return D;
More information about the lldb-commits
mailing list