Skip to content

Commit bbed9e3

Browse files
authored
Merge pull request #7035 from apple/cp/r110861210-keep-enumerating-filesystem-past-broken-symlinks-59
FileSystem::EnumerateDirectory should skip entries w/o Status, not halt
2 parents 3004007 + 61d95fc commit bbed9e3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lldb/source/Host/common/FileSystem.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 13 additions & 0 deletions
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)