aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/VirtualFileSystem.cpp
diff options
context:
space:
mode:
authorKeith Smiley <keithbsmiley@gmail.com>2021-11-13 10:11:25 -0800
committerKeith Smiley <keithbsmiley@gmail.com>2021-11-13 10:11:51 -0800
commitf0cf544d6f6fe6cbca4c07772998272d6bb433d8 (patch)
tree001b69717097df2c8a0939a7d49d19ea2c0f120b /llvm/lib/Support/VirtualFileSystem.cpp
parentb19e823ff9de52f08bb2d35b91305b3c2d3dd0be (diff)
downloadllvm-f0cf544d6f6fe6cbca4c07772998272d6bb433d8.zip
llvm-f0cf544d6f6fe6cbca4c07772998272d6bb433d8.tar.gz
llvm-f0cf544d6f6fe6cbca4c07772998272d6bb433d8.tar.bz2
Revert "[VFS] Use original path when falling back to external FS"
``` /work/omp-vega20-0/openmp-offload-amdgpu-runtime/llvm.src/llvm/lib/Support/VirtualFileSystem.cpp: In static member function 'static llvm::ErrorOr<std::unique_ptr<llvm::vfs::File> > llvm::vfs::File::getWithPath(llvm::ErrorOr<std::unique_ptr<llvm::vfs::File> >, const llvm::Twine&)': /work/omp-vega20-0/openmp-offload-amdgpu-runtime/llvm.src/llvm/lib/Support/VirtualFileSystem.cpp:2084:10: error: could not convert 'F' from 'std::unique_ptr<llvm::vfs::File>' to 'llvm::ErrorOr<std::unique_ptr<llvm::vfs::File> >' return F; ^ ``` This reverts commit c972175649f4bb50d40d911659a04d5620ce6fe0.
Diffstat (limited to 'llvm/lib/Support/VirtualFileSystem.cpp')
-rw-r--r--llvm/lib/Support/VirtualFileSystem.cpp107
1 files changed, 27 insertions, 80 deletions
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index d0ba311..a4abfe1 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -194,7 +194,6 @@ public:
bool RequiresNullTerminator,
bool IsVolatile) override;
std::error_code close() override;
- void setPath(const Twine &Path) override;
};
} // namespace
@@ -230,12 +229,6 @@ std::error_code RealFile::close() {
return EC;
}
-void RealFile::setPath(const Twine &Path) {
- RealName = Path.str();
- if (auto Status = status())
- S = Status.get().copyWithNewName(Status.get(), Path);
-}
-
namespace {
/// A file system according to your operating system.
@@ -646,8 +639,6 @@ public:
}
std::error_code close() override { return {}; }
-
- void setPath(const Twine &Path) override { RequestedName = Path.str(); }
};
} // namespace
@@ -1253,7 +1244,7 @@ directory_iterator RedirectingFileSystem::dir_begin(const Twine &Dir,
}
// Use status to make sure the path exists and refers to a directory.
- ErrorOr<Status> S = status(Path, Dir, *Result);
+ ErrorOr<Status> S = status(Path, *Result);
if (!S) {
if (shouldFallBackToExternalFS(S.getError(), Result->E))
return ExternalFS->dir_begin(Dir, EC);
@@ -1980,68 +1971,47 @@ RedirectingFileSystem::lookupPathImpl(
return make_error_code(llvm::errc::no_such_file_or_directory);
}
-static Status getRedirectedFileStatus(const Twine &OriginalPath,
- bool UseExternalNames,
+static Status getRedirectedFileStatus(const Twine &Path, bool UseExternalNames,
Status ExternalStatus) {
Status S = ExternalStatus;
if (!UseExternalNames)
- S = Status::copyWithNewName(S, OriginalPath);
+ S = Status::copyWithNewName(S, Path);
S.IsVFSMapped = true;
return S;
}
ErrorOr<Status> RedirectingFileSystem::status(
- const Twine &CanonicalPath, const Twine &OriginalPath,
- const RedirectingFileSystem::LookupResult &Result) {
+ const Twine &Path, const RedirectingFileSystem::LookupResult &Result) {
if (Optional<StringRef> ExtRedirect = Result.getExternalRedirect()) {
- SmallString<256> CanonicalRemappedPath((*ExtRedirect).str());
- if (std::error_code EC = makeCanonical(CanonicalRemappedPath))
- return EC;
-
- ErrorOr<Status> S = ExternalFS->status(CanonicalRemappedPath);
+ ErrorOr<Status> S = ExternalFS->status(*ExtRedirect);
if (!S)
return S;
- S = Status::copyWithNewName(*S, *ExtRedirect);
auto *RE = cast<RedirectingFileSystem::RemapEntry>(Result.E);
- return getRedirectedFileStatus(OriginalPath,
- RE->useExternalName(UseExternalNames), *S);
+ return getRedirectedFileStatus(Path, RE->useExternalName(UseExternalNames),
+ *S);
}
auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(Result.E);
- return Status::copyWithNewName(DE->getStatus(), CanonicalPath);
-}
-
-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();
- }
+ return Status::copyWithNewName(DE->getStatus(), Path);
}
-ErrorOr<Status> RedirectingFileSystem::status(const Twine &OriginalPath) {
- SmallString<256> CanonicalPath;
- OriginalPath.toVector(CanonicalPath);
+ErrorOr<Status> RedirectingFileSystem::status(const Twine &Path_) {
+ SmallString<256> Path;
+ Path_.toVector(Path);
- if (std::error_code EC = makeCanonical(CanonicalPath))
+ if (std::error_code EC = makeCanonical(Path))
return EC;
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
- lookupPath(CanonicalPath);
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath(Path);
if (!Result) {
- if (shouldFallBackToExternalFS(Result.getError())) {
- return getExternalStatus(CanonicalPath, OriginalPath);
- }
+ if (shouldFallBackToExternalFS(Result.getError()))
+ return ExternalFS->status(Path);
return Result.getError();
}
- ErrorOr<Status> S = status(CanonicalPath, OriginalPath, *Result);
- if (!S && shouldFallBackToExternalFS(S.getError(), Result->E)) {
- return getExternalStatus(CanonicalPath, OriginalPath);
- }
-
+ ErrorOr<Status> S = status(Path, *Result);
+ if (!S && shouldFallBackToExternalFS(S.getError(), Result->E))
+ S = ExternalFS->status(Path);
return S;
}
@@ -2066,39 +2036,22 @@ public:
}
std::error_code close() override { return InnerFile->close(); }
-
- void setPath(const Twine &Path) override { S = S.copyWithNewName(S, Path); }
};
} // namespace
ErrorOr<std::unique_ptr<File>>
-File::getWithPath(ErrorOr<std::unique_ptr<File>> Result, const Twine &P) {
- if (!Result)
- return Result;
-
- auto F = std::move(*Result);
- auto Name = F->getName();
- if (Name && Name.get() != P.str())
- F->setPath(P);
- return F;
-}
-
-ErrorOr<std::unique_ptr<File>>
-RedirectingFileSystem::openFileForRead(const Twine &OriginalPath) {
- SmallString<256> CanonicalPath;
- OriginalPath.toVector(CanonicalPath);
+RedirectingFileSystem::openFileForRead(const Twine &Path_) {
+ SmallString<256> Path;
+ Path_.toVector(Path);
- if (std::error_code EC = makeCanonical(CanonicalPath))
+ if (std::error_code EC = makeCanonical(Path))
return EC;
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
- lookupPath(CanonicalPath);
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath(Path);
if (!Result) {
if (shouldFallBackToExternalFS(Result.getError()))
- return File::getWithPath(ExternalFS->openFileForRead(CanonicalPath),
- OriginalPath);
-
+ return ExternalFS->openFileForRead(Path);
return Result.getError();
}
@@ -2106,18 +2059,12 @@ RedirectingFileSystem::openFileForRead(const Twine &OriginalPath) {
return make_error_code(llvm::errc::invalid_argument);
StringRef ExtRedirect = *Result->getExternalRedirect();
- SmallString<256> CanonicalRemappedPath(ExtRedirect.str());
- if (std::error_code EC = makeCanonical(CanonicalRemappedPath))
- return EC;
-
auto *RE = cast<RedirectingFileSystem::RemapEntry>(Result->E);
- auto ExternalFile = File::getWithPath(
- ExternalFS->openFileForRead(CanonicalRemappedPath), ExtRedirect);
+ auto ExternalFile = ExternalFS->openFileForRead(ExtRedirect);
if (!ExternalFile) {
if (shouldFallBackToExternalFS(ExternalFile.getError(), Result->E))
- return File::getWithPath(ExternalFS->openFileForRead(CanonicalPath),
- OriginalPath);
+ return ExternalFS->openFileForRead(Path);
return ExternalFile;
}
@@ -2127,7 +2074,7 @@ RedirectingFileSystem::openFileForRead(const Twine &OriginalPath) {
// FIXME: Update the status with the name and VFSMapped.
Status S = getRedirectedFileStatus(
- OriginalPath, RE->useExternalName(UseExternalNames), *ExternalStatus);
+ Path, RE->useExternalName(UseExternalNames), *ExternalStatus);
return std::unique_ptr<File>(
std::make_unique<FileWithFixedStatus>(std::move(*ExternalFile), S));
}