@@ -194,7 +194,6 @@ class RealFile : public File {
194
194
bool RequiresNullTerminator,
195
195
bool IsVolatile) override ;
196
196
std::error_code close () override ;
197
- void setPath (const Twine &Path) override ;
198
197
};
199
198
200
199
} // namespace
@@ -230,12 +229,6 @@ std::error_code RealFile::close() {
230
229
return EC;
231
230
}
232
231
233
- void RealFile::setPath (const Twine &Path) {
234
- RealName = Path.str ();
235
- if (auto Status = status ())
236
- S = Status.get ().copyWithNewName (Status.get (), Path);
237
- }
238
-
239
232
namespace {
240
233
241
234
// / A file system according to your operating system.
@@ -646,8 +639,6 @@ class InMemoryFileAdaptor : public File {
646
639
}
647
640
648
641
std::error_code close () override { return {}; }
649
-
650
- void setPath (const Twine &Path) override { RequestedName = Path.str (); }
651
642
};
652
643
} // namespace
653
644
@@ -1253,7 +1244,7 @@ directory_iterator RedirectingFileSystem::dir_begin(const Twine &Dir,
1253
1244
}
1254
1245
1255
1246
// Use status to make sure the path exists and refers to a directory.
1256
- ErrorOr<Status> S = status (Path, Dir, *Result);
1247
+ ErrorOr<Status> S = status (Path, *Result);
1257
1248
if (!S) {
1258
1249
if (shouldFallBackToExternalFS (S.getError (), Result->E ))
1259
1250
return ExternalFS->dir_begin (Dir, EC);
@@ -1980,68 +1971,47 @@ RedirectingFileSystem::lookupPathImpl(
1980
1971
return make_error_code (llvm::errc::no_such_file_or_directory);
1981
1972
}
1982
1973
1983
- static Status getRedirectedFileStatus (const Twine &OriginalPath,
1984
- bool UseExternalNames,
1974
+ static Status getRedirectedFileStatus (const Twine &Path, bool UseExternalNames,
1985
1975
Status ExternalStatus) {
1986
1976
Status S = ExternalStatus;
1987
1977
if (!UseExternalNames)
1988
- S = Status::copyWithNewName (S, OriginalPath );
1978
+ S = Status::copyWithNewName (S, Path );
1989
1979
S.IsVFSMapped = true ;
1990
1980
return S;
1991
1981
}
1992
1982
1993
1983
ErrorOr<Status> RedirectingFileSystem::status (
1994
- const Twine &CanonicalPath, const Twine &OriginalPath,
1995
- const RedirectingFileSystem::LookupResult &Result) {
1984
+ const Twine &Path, const RedirectingFileSystem::LookupResult &Result) {
1996
1985
if (Optional<StringRef> ExtRedirect = Result.getExternalRedirect ()) {
1997
- SmallString<256 > CanonicalRemappedPath ((*ExtRedirect).str ());
1998
- if (std::error_code EC = makeCanonical (CanonicalRemappedPath))
1999
- return EC;
2000
-
2001
- ErrorOr<Status> S = ExternalFS->status (CanonicalRemappedPath);
1986
+ ErrorOr<Status> S = ExternalFS->status (*ExtRedirect);
2002
1987
if (!S)
2003
1988
return S;
2004
- S = Status::copyWithNewName (*S, *ExtRedirect);
2005
1989
auto *RE = cast<RedirectingFileSystem::RemapEntry>(Result.E );
2006
- return getRedirectedFileStatus (OriginalPath ,
2007
- RE-> useExternalName (UseExternalNames), *S);
1990
+ return getRedirectedFileStatus (Path, RE-> useExternalName (UseExternalNames) ,
1991
+ *S);
2008
1992
}
2009
1993
2010
1994
auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(Result.E );
2011
- return Status::copyWithNewName (DE->getStatus (), CanonicalPath);
2012
- }
2013
-
2014
- ErrorOr<Status>
2015
- RedirectingFileSystem::getExternalStatus (const Twine &CanonicalPath,
2016
- const Twine &OriginalPath) const {
2017
- if (auto Result = ExternalFS->status (CanonicalPath)) {
2018
- return Result.get ().copyWithNewName (Result.get (), OriginalPath);
2019
- } else {
2020
- return Result.getError ();
2021
- }
1995
+ return Status::copyWithNewName (DE->getStatus (), Path);
2022
1996
}
2023
1997
2024
- ErrorOr<Status> RedirectingFileSystem::status (const Twine &OriginalPath ) {
2025
- SmallString<256 > CanonicalPath ;
2026
- OriginalPath .toVector (CanonicalPath );
1998
+ ErrorOr<Status> RedirectingFileSystem::status (const Twine &Path_ ) {
1999
+ SmallString<256 > Path ;
2000
+ Path_ .toVector (Path );
2027
2001
2028
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2002
+ if (std::error_code EC = makeCanonical (Path ))
2029
2003
return EC;
2030
2004
2031
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2032
- lookupPath (CanonicalPath);
2005
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2033
2006
if (!Result) {
2034
- if (shouldFallBackToExternalFS (Result.getError ())) {
2035
- return getExternalStatus (CanonicalPath, OriginalPath);
2036
- }
2007
+ if (shouldFallBackToExternalFS (Result.getError ()))
2008
+ return ExternalFS->status (Path);
2037
2009
return Result.getError ();
2038
2010
}
2039
2011
2040
- ErrorOr<Status> S = status (CanonicalPath, OriginalPath, *Result);
2041
- if (!S && shouldFallBackToExternalFS (S.getError (), Result->E )) {
2042
- return getExternalStatus (CanonicalPath, OriginalPath);
2043
- }
2044
-
2012
+ ErrorOr<Status> S = status (Path, *Result);
2013
+ if (!S && shouldFallBackToExternalFS (S.getError (), Result->E ))
2014
+ S = ExternalFS->status (Path);
2045
2015
return S;
2046
2016
}
2047
2017
@@ -2066,58 +2036,35 @@ class FileWithFixedStatus : public File {
2066
2036
}
2067
2037
2068
2038
std::error_code close () override { return InnerFile->close (); }
2069
-
2070
- void setPath (const Twine &Path) override { S = S.copyWithNewName (S, Path); }
2071
2039
};
2072
2040
2073
2041
} // namespace
2074
2042
2075
2043
ErrorOr<std::unique_ptr<File>>
2076
- File::getWithPath (ErrorOr<std::unique_ptr<File>> Result, const Twine &P) {
2077
- if (!Result)
2078
- return Result;
2079
-
2080
- auto F = std::move (*Result);
2081
- auto Name = F->getName ();
2082
- if (Name && Name.get () != P.str ())
2083
- F->setPath (P);
2084
- return F;
2085
- }
2086
-
2087
- ErrorOr<std::unique_ptr<File>>
2088
- RedirectingFileSystem::openFileForRead (const Twine &OriginalPath) {
2089
- SmallString<256 > CanonicalPath;
2090
- OriginalPath.toVector (CanonicalPath);
2044
+ RedirectingFileSystem::openFileForRead (const Twine &Path_) {
2045
+ SmallString<256 > Path;
2046
+ Path_.toVector (Path);
2091
2047
2092
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2048
+ if (std::error_code EC = makeCanonical (Path ))
2093
2049
return EC;
2094
2050
2095
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2096
- lookupPath (CanonicalPath);
2051
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2097
2052
if (!Result) {
2098
2053
if (shouldFallBackToExternalFS (Result.getError ()))
2099
- return File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2100
- OriginalPath);
2101
-
2054
+ return ExternalFS->openFileForRead (Path);
2102
2055
return Result.getError ();
2103
2056
}
2104
2057
2105
2058
if (!Result->getExternalRedirect ()) // FIXME: errc::not_a_file?
2106
2059
return make_error_code (llvm::errc::invalid_argument);
2107
2060
2108
2061
StringRef ExtRedirect = *Result->getExternalRedirect ();
2109
- SmallString<256 > CanonicalRemappedPath (ExtRedirect.str ());
2110
- if (std::error_code EC = makeCanonical (CanonicalRemappedPath))
2111
- return EC;
2112
-
2113
2062
auto *RE = cast<RedirectingFileSystem::RemapEntry>(Result->E );
2114
2063
2115
- auto ExternalFile = File::getWithPath (
2116
- ExternalFS->openFileForRead (CanonicalRemappedPath), ExtRedirect);
2064
+ auto ExternalFile = ExternalFS->openFileForRead (ExtRedirect);
2117
2065
if (!ExternalFile) {
2118
2066
if (shouldFallBackToExternalFS (ExternalFile.getError (), Result->E ))
2119
- return File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2120
- OriginalPath);
2067
+ return ExternalFS->openFileForRead (Path);
2121
2068
return ExternalFile;
2122
2069
}
2123
2070
@@ -2127,7 +2074,7 @@ RedirectingFileSystem::openFileForRead(const Twine &OriginalPath) {
2127
2074
2128
2075
// FIXME: Update the status with the name and VFSMapped.
2129
2076
Status S = getRedirectedFileStatus (
2130
- OriginalPath , RE->useExternalName (UseExternalNames), *ExternalStatus);
2077
+ Path , RE->useExternalName (UseExternalNames), *ExternalStatus);
2131
2078
return std::unique_ptr<File>(
2132
2079
std::make_unique<FileWithFixedStatus>(std::move (*ExternalFile), S));
2133
2080
}
0 commit comments