Skip to content

Commit 8c8d349

Browse files
committed
[lldb/Utility] Don't forward directories to the file collector
The VFS mapping writer assumes that all the paths it gets are files. When passed a directory, it ends up as a file in the VFS mapping twice, once as a file and once as a directory. { 'type': 'file', 'name': "Output", 'external-contents': "/root/path/to/Output" }, { 'type': 'directory', 'name': "Output", 'contents': [ ... ] } (cherry picked from commit 4c2b0a6)
1 parent 5f1caca commit 8c8d349

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lldb/include/lldb/Host/FileSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class FileSystem {
186186
}
187187

188188
private:
189+
void AddFile(const llvm::Twine &file);
189190
static llvm::Optional<FileSystem> &InstanceImpl();
190191
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
191192
FileCollector *m_collector;

lldb/source/Host/common/FileSystem.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ void FileSystem::Resolve(FileSpec &file_spec) {
279279
std::shared_ptr<DataBufferLLVM>
280280
FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size,
281281
uint64_t offset) {
282-
if (m_collector)
283-
m_collector->AddFile(path);
282+
AddFile(path);
284283

285284
const bool is_volatile = !IsLocal(path);
286285
const ErrorOr<std::string> external_path = GetExternalPath(path);
@@ -417,8 +416,7 @@ static mode_t GetOpenMode(uint32_t permissions) {
417416

418417
Status FileSystem::Open(File &File, const FileSpec &file_spec, uint32_t options,
419418
uint32_t permissions, bool should_close_fd) {
420-
if (m_collector)
421-
m_collector->AddFile(file_spec);
419+
AddFile(file_spec.GetPath());
422420

423421
if (File.IsValid())
424422
File.Close();
@@ -469,3 +467,9 @@ ErrorOr<std::string> FileSystem::GetExternalPath(const llvm::Twine &path) {
469467
ErrorOr<std::string> FileSystem::GetExternalPath(const FileSpec &file_spec) {
470468
return GetExternalPath(file_spec.GetPath());
471469
}
470+
471+
void FileSystem::AddFile(const llvm::Twine &file) {
472+
if (m_collector && !llvm::sys::fs::is_directory(file)) {
473+
m_collector->addFile(file);
474+
}
475+
}

0 commit comments

Comments
 (0)