diff options
author | Ben Barham <ben_barham@apple.com> | 2022-04-11 14:50:28 -0700 |
---|---|---|
committer | Ben Barham <ben_barham@apple.com> | 2022-04-11 14:52:48 -0700 |
commit | fe2478d44e4f7f191c43fef629ac7a23d0251e72 (patch) | |
tree | 176fd46b0cd3aab8bc45b3fdc4392b96767c215d /llvm/lib/Support/VirtualFileSystem.cpp | |
parent | 8b5e4c038ed7d79e377afd19e804b0b2e5419aa3 (diff) | |
download | llvm-fe2478d44e4f7f191c43fef629ac7a23d0251e72.zip llvm-fe2478d44e4f7f191c43fef629ac7a23d0251e72.tar.gz llvm-fe2478d44e4f7f191c43fef629ac7a23d0251e72.tar.bz2 |
[VFS] RedirectingFileSystem only replace path if not already mapped
If the `ExternalFS` has already remapped to an external path then
`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).
For now this is accomplished through the use of a new
`ExposesExternalVFSPath` field on `vfs::Status`. This flag is true when
the `Status` has an external path that's different from its virtual
path, ie. the contained path is the external path. See the plan in
`FileManager::getFileRef` for where this is going - eventually we won't
need `IsVFSMapped` any more and all returned paths should be virtual.
Resolves rdar://90578880 and llvm-project#53306.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D123398
Diffstat (limited to 'llvm/lib/Support/VirtualFileSystem.cpp')
-rw-r--r-- | llvm/lib/Support/VirtualFileSystem.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index cb34fa60..c9273f0 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -2163,9 +2163,16 @@ RedirectingFileSystem::lookupPathImpl( static Status getRedirectedFileStatus(const Twine &OriginalPath, bool UseExternalNames, Status ExternalStatus) { + // The path has been mapped by some nested VFS and exposes an external path, + // don't override it with the original path. + if (ExternalStatus.ExposesExternalVFSPath) + return ExternalStatus; + Status S = ExternalStatus; if (!UseExternalNames) S = Status::copyWithNewName(S, OriginalPath); + else + S.ExposesExternalVFSPath = true; S.IsVFSMapped = true; return S; } @@ -2194,11 +2201,13 @@ ErrorOr<Status> RedirectingFileSystem::status( ErrorOr<Status> RedirectingFileSystem::getExternalStatus(const Twine &CanonicalPath, const Twine &OriginalPath) const { - if (auto Result = ExternalFS->status(CanonicalPath)) { - return Result.get().copyWithNewName(Result.get(), OriginalPath); - } else { - return Result.getError(); - } + auto Result = ExternalFS->status(CanonicalPath); + + // The path has been mapped by some nested VFS, don't override it with the + // original path. + if (!Result || Result->ExposesExternalVFSPath) + return Result; + return Status::copyWithNewName(Result.get(), OriginalPath); } ErrorOr<Status> RedirectingFileSystem::status(const Twine &OriginalPath) { @@ -2268,7 +2277,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 exposing an + // external path. + if (!Result || (*Result)->status()->ExposesExternalVFSPath) return Result; ErrorOr<std::unique_ptr<File>> F = std::move(*Result); |