aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/VirtualFileSystem.cpp
diff options
context:
space:
mode:
authorBen Barham <ben_barham@apple.com>2022-03-27 14:08:48 -0700
committerBen Barham <ben_barham@apple.com>2022-03-30 11:52:41 -0700
commit3fda0edc51fd68192a30e302d45db081bb02d7f9 (patch)
tree343d86238d3259d5574a9a990c5f2a5f0523df5e /llvm/lib/Support/VirtualFileSystem.cpp
parent4477500533281c90c6ce70eb87271f61fd6a415f (diff)
downloadllvm-3fda0edc51fd68192a30e302d45db081bb02d7f9.zip
llvm-3fda0edc51fd68192a30e302d45db081bb02d7f9.tar.gz
llvm-3fda0edc51fd68192a30e302d45db081bb02d7f9.tar.bz2
[VFS] RedirectingFileSystem only replace path if not already mapped
If the `ExternalFS` has already remapped a path then the `RedirectingFileSystem` should not change it to the originally provided path. This fixes the original path always being used if multiple VFS overlays were provided and the path wasn't found in the highest (ie. first in the chain). This also renames `IsVFSMapped` to `ExposesExternalVFSPath` and only sets it if `UseExternalName` is true. This flag then represents that the `Status` has an external path that's different from its virtual path. Right now the contained path is still the external path, but further PRs will change this to *always* be the virtual path. Clients that need the external can then request it specifically. Note that even though `ExposesExternalVFSPath` isn't set for all VFS-mapped paths, `IsVFSMapped` was only being used by a hack in `FileManager` that was specific to module searching. In that case `UseExternalNames` is always `true` and so that hack still applies. Resolves rdar://90578880 and llvm-project#53306. Differential Revision: https://reviews.llvm.org/D122549
Diffstat (limited to 'llvm/lib/Support/VirtualFileSystem.cpp')
-rw-r--r--llvm/lib/Support/VirtualFileSystem.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index cb34fa60..14e9f02 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -2163,10 +2163,16 @@ RedirectingFileSystem::lookupPathImpl(
static Status getRedirectedFileStatus(const Twine &OriginalPath,
bool UseExternalNames,
Status ExternalStatus) {
+ // The path has been mapped by some nested VFS, don't override it with the
+ // original path.
+ if (ExternalStatus.ExposesExternalVFSPath)
+ return ExternalStatus;
+
Status S = ExternalStatus;
if (!UseExternalNames)
S = Status::copyWithNewName(S, OriginalPath);
- S.IsVFSMapped = true;
+ else
+ S.ExposesExternalVFSPath = true;
return S;
}
@@ -2268,7 +2274,9 @@ public:
ErrorOr<std::unique_ptr<File>>
File::getWithPath(ErrorOr<std::unique_ptr<File>> Result, const Twine &P) {
- if (!Result)
+ // See \c getRedirectedFileStatus - don't update path if it's already been
+ // mapped.
+ if (!Result || (*Result)->status()->ExposesExternalVFSPath)
return Result;
ErrorOr<std::unique_ptr<File>> F = std::move(*Result);