[Lldb-commits] [PATCH] D153822: FileSystem::EnumerateDirectory should keep iterating if one entry has an invalid Status
Jason Molenda via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 26 17:16:36 PDT 2023
jasonmolenda created this revision.
jasonmolenda added a reviewer: JDevlieghere.
jasonmolenda added a project: LLDB.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.
EnumerateDirectory gets the vfs::Status of each file entry, to check if we are asked to report on this file type, and if we can't get the Status, it stops the directory search. Instead, if it can't get the Status of a directory entry, it should skip that entry and continue searching.
This happens with a broken symlink - the link points to another file, but that file doesn't exist, and the Status returned is of the destination file. When we can't get the destination file Status, an error code is returned.
Add a test case to FileSystemTests unittest.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153822
Files:
lldb/source/Host/common/FileSystem.cpp
lldb/unittests/Host/FileSystemTest.cpp
Index: lldb/unittests/Host/FileSystemTest.cpp
===================================================================
--- lldb/unittests/Host/FileSystemTest.cpp
+++ lldb/unittests/Host/FileSystemTest.cpp
@@ -51,6 +51,11 @@
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 @@
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 @@
D->addRegularFile("/foo");
D->addDirectory("/bar");
D->addSymlink("/baz");
+ D->addBrokenSymlink("/lux");
D->addRegularFile("/qux", ~sys::fs::perms::all_read);
D->setCurrentWorkingDirectory("/");
return D;
Index: lldb/source/Host/common/FileSystem.cpp
===================================================================
--- lldb/source/Host/common/FileSystem.cpp
+++ lldb/source/Host/common/FileSystem.cpp
@@ -192,7 +192,7 @@
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())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153822.534792.patch
Type: text/x-patch
Size: 1817 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230627/6a22d76f/attachment.bin>
More information about the lldb-commits
mailing list