Page MenuHomePhabricator

[VirtualFileSystem] Support directory entries in the YAMLVFSWriter
ClosedPublic

Authored by JDevlieghere on Mar 23 2020, 11:17 PM.

Details

Summary

The current implementation of the JSONWriter does not support writing out directory entries. Earlier today I added a unit test to illustrate the problem. When an entry is added to the YAMLVFSWriter and the path is a directory, it will incorrectly emit the directory as a file, and any files inside that directory will not be found by the VFS.

Usually it's possible to work around the issue by only adding leaf nodes (files) to the YAMLVFSWriter. However, this doesn't work for representing empty directories. This is a real issue for clients of the VFS that want to iterate over a directory. The directory not being there is not the same as the directory being empty.

This is not just a hypothetical problem but a real issue. The FileCollector does not differentiate between file and directory paths. I temporarily worked around the issue for LLDB by ignoring directories, but I suspect this will prove problematic sooner rather than later.

This patch fixes the issue by extending the JSONWriter to support writing out directory entries. We have to special-case the first entry, but otherwise it's just a matter of emitting a directory entry instead of a file entry.

Diff Detail

Event Timeline

JDevlieghere created this revision.Mar 23 2020, 11:17 PM

It looks like you're now adding a dependency on a real filesystem to the VFS writer due to calls to fs::is_directory. I think it should be possible to use a VFS write to construct a VFS file without an underlying filesystem, or with an underlying filesystem that doesn't represent the state of your constructed VFS. Is there another way to achieve this goal without depending on the underlying filesystem?

JDevlieghere planned changes to this revision.Mar 27 2020, 1:51 PM

It looks like you're now adding a dependency on a real filesystem to the VFS writer due to calls to fs::is_directory. I think it should be possible to use a VFS write to construct a VFS file without an underlying filesystem, or with an underlying filesystem that doesn't represent the state of your constructed VFS. Is there another way to achieve this goal without depending on the underlying filesystem?

Good point. We could move the check out of the writer and make it the responsibility of the caller, so instead of having just addFile we'd also have an addDirectory. I'll update the patch.

arphaman accepted this revision.Mar 27 2020, 2:59 PM

Great, that looks better, thanks! LGTM

This revision is now accepted and ready to land.Mar 27 2020, 2:59 PM
This revision was automatically updated to reflect the committed changes.