@@ -1344,7 +1344,7 @@ std::error_code RedirectingFileSystem::isLocal(const Twine &Path_,
1344
1344
SmallString<256 > Path;
1345
1345
Path_.toVector (Path);
1346
1346
1347
- if (makeCanonical (Path))
1347
+ if (makeAbsolute (Path))
1348
1348
return {};
1349
1349
1350
1350
return ExternalFS->isLocal (Path, Result);
@@ -1411,7 +1411,7 @@ directory_iterator RedirectingFileSystem::dir_begin(const Twine &Dir,
1411
1411
SmallString<256 > Path;
1412
1412
Dir.toVector (Path);
1413
1413
1414
- EC = makeCanonical (Path);
1414
+ EC = makeAbsolute (Path);
1415
1415
if (EC)
1416
1416
return {};
1417
1417
@@ -2261,8 +2261,8 @@ void RedirectingFileSystem::LookupResult::getPath(
2261
2261
llvm::sys::path::append (Result, E->getName ());
2262
2262
}
2263
2263
2264
- std::error_code
2265
- RedirectingFileSystem::makeCanonical ( SmallVectorImpl<char > &Path) const {
2264
+ std::error_code RedirectingFileSystem::makeCanonicalForLookup (
2265
+ SmallVectorImpl<char > &Path) const {
2266
2266
if (std::error_code EC = makeAbsolute (Path))
2267
2267
return EC;
2268
2268
@@ -2277,12 +2277,16 @@ RedirectingFileSystem::makeCanonical(SmallVectorImpl<char> &Path) const {
2277
2277
2278
2278
ErrorOr<RedirectingFileSystem::LookupResult>
2279
2279
RedirectingFileSystem::lookupPath (StringRef Path) const {
2280
+ llvm::SmallString<128 > CanonicalPath (Path);
2281
+ if (std::error_code EC = makeCanonicalForLookup (CanonicalPath))
2282
+ return EC;
2283
+
2280
2284
// RedirectOnly means the VFS is always used.
2281
2285
if (UsageTrackingActive && Redirection == RedirectKind::RedirectOnly)
2282
2286
HasBeenUsed = true ;
2283
2287
2284
- sys::path::const_iterator Start = sys::path::begin (Path );
2285
- sys::path::const_iterator End = sys::path::end (Path );
2288
+ sys::path::const_iterator Start = sys::path::begin (CanonicalPath );
2289
+ sys::path::const_iterator End = sys::path::end (CanonicalPath );
2286
2290
llvm::SmallVector<Entry *, 32 > Entries;
2287
2291
for (const auto &Root : Roots) {
2288
2292
ErrorOr<RedirectingFileSystem::LookupResult> Result =
@@ -2358,14 +2362,14 @@ static Status getRedirectedFileStatus(const Twine &OriginalPath,
2358
2362
}
2359
2363
2360
2364
ErrorOr<Status> RedirectingFileSystem::status (
2361
- const Twine &CanonicalPath , const Twine &OriginalPath,
2365
+ const Twine &LookupPath , const Twine &OriginalPath,
2362
2366
const RedirectingFileSystem::LookupResult &Result) {
2363
2367
if (std::optional<StringRef> ExtRedirect = Result.getExternalRedirect ()) {
2364
- SmallString<256 > CanonicalRemappedPath ((*ExtRedirect).str ());
2365
- if (std::error_code EC = makeCanonical (CanonicalRemappedPath ))
2368
+ SmallString<256 > RemappedPath ((*ExtRedirect).str ());
2369
+ if (std::error_code EC = makeAbsolute (RemappedPath ))
2366
2370
return EC;
2367
2371
2368
- ErrorOr<Status> S = ExternalFS->status (CanonicalRemappedPath );
2372
+ ErrorOr<Status> S = ExternalFS->status (RemappedPath );
2369
2373
if (!S)
2370
2374
return S;
2371
2375
S = Status::copyWithNewName (*S, *ExtRedirect);
@@ -2375,13 +2379,13 @@ ErrorOr<Status> RedirectingFileSystem::status(
2375
2379
}
2376
2380
2377
2381
auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(Result.E );
2378
- return Status::copyWithNewName (DE->getStatus (), CanonicalPath );
2382
+ return Status::copyWithNewName (DE->getStatus (), LookupPath );
2379
2383
}
2380
2384
2381
2385
ErrorOr<Status>
2382
- RedirectingFileSystem::getExternalStatus (const Twine &CanonicalPath ,
2386
+ RedirectingFileSystem::getExternalStatus (const Twine &LookupPath ,
2383
2387
const Twine &OriginalPath) const {
2384
- auto Result = ExternalFS->status (CanonicalPath );
2388
+ auto Result = ExternalFS->status (LookupPath );
2385
2389
2386
2390
// The path has been mapped by some nested VFS, don't override it with the
2387
2391
// original path.
@@ -2391,38 +2395,37 @@ RedirectingFileSystem::getExternalStatus(const Twine &CanonicalPath,
2391
2395
}
2392
2396
2393
2397
ErrorOr<Status> RedirectingFileSystem::status (const Twine &OriginalPath) {
2394
- SmallString<256 > CanonicalPath ;
2395
- OriginalPath.toVector (CanonicalPath );
2398
+ SmallString<256 > Path ;
2399
+ OriginalPath.toVector (Path );
2396
2400
2397
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2401
+ if (std::error_code EC = makeAbsolute (Path ))
2398
2402
return EC;
2399
2403
2400
2404
if (Redirection == RedirectKind::Fallback) {
2401
2405
// Attempt to find the original file first, only falling back to the
2402
2406
// mapped file if that fails.
2403
- ErrorOr<Status> S = getExternalStatus (CanonicalPath , OriginalPath);
2407
+ ErrorOr<Status> S = getExternalStatus (Path , OriginalPath);
2404
2408
if (S)
2405
2409
return S;
2406
2410
}
2407
2411
2408
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2409
- lookupPath (CanonicalPath);
2412
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2410
2413
if (!Result) {
2411
2414
// Was not able to map file, fallthrough to using the original path if
2412
2415
// that was the specified redirection type.
2413
2416
if (Redirection == RedirectKind::Fallthrough &&
2414
2417
isFileNotFound (Result.getError ()))
2415
- return getExternalStatus (CanonicalPath , OriginalPath);
2418
+ return getExternalStatus (Path , OriginalPath);
2416
2419
return Result.getError ();
2417
2420
}
2418
2421
2419
- ErrorOr<Status> S = status (CanonicalPath , OriginalPath, *Result);
2422
+ ErrorOr<Status> S = status (Path , OriginalPath, *Result);
2420
2423
if (!S && Redirection == RedirectKind::Fallthrough &&
2421
2424
isFileNotFound (S.getError (), Result->E )) {
2422
2425
// Mapped the file but it wasn't found in the underlying filesystem,
2423
2426
// fallthrough to using the original path if that was the specified
2424
2427
// redirection type.
2425
- return getExternalStatus (CanonicalPath , OriginalPath);
2428
+ return getExternalStatus (Path , OriginalPath);
2426
2429
}
2427
2430
2428
2431
return S;
@@ -2471,53 +2474,49 @@ File::getWithPath(ErrorOr<std::unique_ptr<File>> Result, const Twine &P) {
2471
2474
2472
2475
ErrorOr<std::unique_ptr<File>>
2473
2476
RedirectingFileSystem::openFileForRead (const Twine &OriginalPath) {
2474
- SmallString<256 > CanonicalPath ;
2475
- OriginalPath.toVector (CanonicalPath );
2477
+ SmallString<256 > Path ;
2478
+ OriginalPath.toVector (Path );
2476
2479
2477
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2480
+ if (std::error_code EC = makeAbsolute (Path ))
2478
2481
return EC;
2479
2482
2480
2483
if (Redirection == RedirectKind::Fallback) {
2481
2484
// Attempt to find the original file first, only falling back to the
2482
2485
// mapped file if that fails.
2483
- auto F = File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2484
- OriginalPath);
2486
+ auto F = File::getWithPath (ExternalFS->openFileForRead (Path), OriginalPath);
2485
2487
if (F)
2486
2488
return F;
2487
2489
}
2488
2490
2489
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2490
- lookupPath (CanonicalPath);
2491
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2491
2492
if (!Result) {
2492
2493
// Was not able to map file, fallthrough to using the original path if
2493
2494
// that was the specified redirection type.
2494
2495
if (Redirection == RedirectKind::Fallthrough &&
2495
2496
isFileNotFound (Result.getError ()))
2496
- return File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2497
- OriginalPath);
2497
+ return File::getWithPath (ExternalFS->openFileForRead (Path), OriginalPath);
2498
2498
return Result.getError ();
2499
2499
}
2500
2500
2501
2501
if (!Result->getExternalRedirect ()) // FIXME: errc::not_a_file?
2502
2502
return make_error_code (llvm::errc::invalid_argument);
2503
2503
2504
2504
StringRef ExtRedirect = *Result->getExternalRedirect ();
2505
- SmallString<256 > CanonicalRemappedPath (ExtRedirect.str ());
2506
- if (std::error_code EC = makeCanonical (CanonicalRemappedPath ))
2505
+ SmallString<256 > RemappedPath (ExtRedirect.str ());
2506
+ if (std::error_code EC = makeAbsolute (RemappedPath ))
2507
2507
return EC;
2508
2508
2509
2509
auto *RE = cast<RedirectingFileSystem::RemapEntry>(Result->E );
2510
2510
2511
- auto ExternalFile = File::getWithPath (
2512
- ExternalFS->openFileForRead (CanonicalRemappedPath ), ExtRedirect);
2511
+ auto ExternalFile =
2512
+ File::getWithPath ( ExternalFS->openFileForRead (RemappedPath ), ExtRedirect);
2513
2513
if (!ExternalFile) {
2514
2514
if (Redirection == RedirectKind::Fallthrough &&
2515
2515
isFileNotFound (ExternalFile.getError (), Result->E )) {
2516
2516
// Mapped the file but it wasn't found in the underlying filesystem,
2517
2517
// fallthrough to using the original path if that was the specified
2518
2518
// redirection type.
2519
- return File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2520
- OriginalPath);
2519
+ return File::getWithPath (ExternalFS->openFileForRead (Path), OriginalPath);
2521
2520
}
2522
2521
return ExternalFile;
2523
2522
}
@@ -2537,28 +2536,27 @@ RedirectingFileSystem::openFileForRead(const Twine &OriginalPath) {
2537
2536
std::error_code
2538
2537
RedirectingFileSystem::getRealPath (const Twine &OriginalPath,
2539
2538
SmallVectorImpl<char > &Output) const {
2540
- SmallString<256 > CanonicalPath ;
2541
- OriginalPath.toVector (CanonicalPath );
2539
+ SmallString<256 > Path ;
2540
+ OriginalPath.toVector (Path );
2542
2541
2543
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2542
+ if (std::error_code EC = makeAbsolute (Path ))
2544
2543
return EC;
2545
2544
2546
2545
if (Redirection == RedirectKind::Fallback) {
2547
2546
// Attempt to find the original file first, only falling back to the
2548
2547
// mapped file if that fails.
2549
- std::error_code EC = ExternalFS->getRealPath (CanonicalPath , Output);
2548
+ std::error_code EC = ExternalFS->getRealPath (Path , Output);
2550
2549
if (!EC)
2551
2550
return EC;
2552
2551
}
2553
2552
2554
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2555
- lookupPath (CanonicalPath);
2553
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2556
2554
if (!Result) {
2557
2555
// Was not able to map file, fallthrough to using the original path if
2558
2556
// that was the specified redirection type.
2559
2557
if (Redirection == RedirectKind::Fallthrough &&
2560
2558
isFileNotFound (Result.getError ()))
2561
- return ExternalFS->getRealPath (CanonicalPath , Output);
2559
+ return ExternalFS->getRealPath (Path , Output);
2562
2560
return Result.getError ();
2563
2561
}
2564
2562
@@ -2571,7 +2569,7 @@ RedirectingFileSystem::getRealPath(const Twine &OriginalPath,
2571
2569
// Mapped the file but it wasn't found in the underlying filesystem,
2572
2570
// fallthrough to using the original path if that was the specified
2573
2571
// redirection type.
2574
- return ExternalFS->getRealPath (CanonicalPath , Output);
2572
+ return ExternalFS->getRealPath (Path , Output);
2575
2573
}
2576
2574
return P;
2577
2575
}
0 commit comments