Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61d95fc

Browse files
committed
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 (cherry picked from commit 2c1108f)
1 parent 3004007 commit 61d95fc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lldb/source/Host/common/FileSystem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void FileSystem::EnumerateDirectory(Twine path, bool find_directories,
191191
const auto &Item = *Iter;
192192
ErrorOr<vfs::Status> Status = m_fs->status(Item.path());
193193
if (!Status)
194-
break;
194+
continue;
195195
if (!find_files && Status->isRegularFile())
196196
continue;
197197
if (!find_directories && Status->isDirectory())

lldb/unittests/Host/FileSystemTest.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class DummyFileSystem : public vfs::FileSystem {
5151
FilesAndDirs.find(Path.str());
5252
if (I == FilesAndDirs.end())
5353
return make_error_code(llvm::errc::no_such_file_or_directory);
54+
// Simulate a broken symlink, where it points to a file/dir that
55+
// does not exist.
56+
if (I->second.isSymlink() &&
57+
I->second.getPermissions() == sys::fs::perms::no_perms)
58+
return std::error_code(ENOENT, std::generic_category());
5459
return I->second;
5560
}
5661
ErrorOr<std::unique_ptr<vfs::File>>
@@ -152,6 +157,13 @@ class DummyFileSystem : public vfs::FileSystem {
152157
sys::fs::file_type::symlink_file, sys::fs::all_all);
153158
addEntry(Path, S);
154159
}
160+
161+
void addBrokenSymlink(StringRef Path) {
162+
vfs::Status S(Path, UniqueID(FSID, FileID++),
163+
std::chrono::system_clock::now(), 0, 0, 0,
164+
sys::fs::file_type::symlink_file, sys::fs::no_perms);
165+
addEntry(Path, S);
166+
}
155167
};
156168
} // namespace
157169

@@ -178,6 +190,7 @@ static IntrusiveRefCntPtr<DummyFileSystem> GetSimpleDummyFS() {
178190
D->addRegularFile("/foo");
179191
D->addDirectory("/bar");
180192
D->addSymlink("/baz");
193+
D->addBrokenSymlink("/lux");
181194
D->addRegularFile("/qux", ~sys::fs::perms::all_read);
182195
D->setCurrentWorkingDirectory("/");
183196
return D;

0 commit comments

Comments
 (0)