@@ -1373,7 +1373,7 @@ std::error_code RedirectingFileSystem::isLocal(const Twine &Path_,
1373
1373
SmallString<256 > Path;
1374
1374
Path_.toVector (Path);
1375
1375
1376
- if (std::error_code EC = makeCanonical (Path))
1376
+ if (makeAbsolute (Path))
1377
1377
return {};
1378
1378
1379
1379
return ExternalFS->isLocal (Path, Result);
@@ -1440,7 +1440,7 @@ directory_iterator RedirectingFileSystem::dir_begin(const Twine &Dir,
1440
1440
SmallString<256 > Path;
1441
1441
Dir.toVector (Path);
1442
1442
1443
- EC = makeCanonical (Path);
1443
+ EC = makeAbsolute (Path);
1444
1444
if (EC)
1445
1445
return {};
1446
1446
@@ -2290,8 +2290,8 @@ void RedirectingFileSystem::LookupResult::getPath(
2290
2290
llvm::sys::path::append (Result, E->getName ());
2291
2291
}
2292
2292
2293
- std::error_code
2294
- RedirectingFileSystem::makeCanonical ( SmallVectorImpl<char > &Path) const {
2293
+ std::error_code RedirectingFileSystem::makeCanonicalForLookup (
2294
+ SmallVectorImpl<char > &Path) const {
2295
2295
if (std::error_code EC = makeAbsolute (Path))
2296
2296
return EC;
2297
2297
@@ -2306,12 +2306,16 @@ RedirectingFileSystem::makeCanonical(SmallVectorImpl<char> &Path) const {
2306
2306
2307
2307
ErrorOr<RedirectingFileSystem::LookupResult>
2308
2308
RedirectingFileSystem::lookupPath (StringRef Path) const {
2309
+ llvm::SmallString<128 > CanonicalPath (Path);
2310
+ if (std::error_code EC = makeCanonicalForLookup (CanonicalPath))
2311
+ return EC;
2312
+
2309
2313
// RedirectOnly means the VFS is always used.
2310
2314
if (UsageTrackingActive && Redirection == RedirectKind::RedirectOnly)
2311
2315
HasBeenUsed = true ;
2312
2316
2313
- sys::path::const_iterator Start = sys::path::begin (Path );
2314
- sys::path::const_iterator End = sys::path::end (Path );
2317
+ sys::path::const_iterator Start = sys::path::begin (CanonicalPath );
2318
+ sys::path::const_iterator End = sys::path::end (CanonicalPath );
2315
2319
llvm::SmallVector<Entry *, 32 > Entries;
2316
2320
for (const auto &Root : Roots) {
2317
2321
ErrorOr<RedirectingFileSystem::LookupResult> Result =
@@ -2388,14 +2392,14 @@ static Status getRedirectedFileStatus(const Twine &OriginalPath,
2388
2392
}
2389
2393
2390
2394
ErrorOr<Status> RedirectingFileSystem::status (
2391
- const Twine &CanonicalPath , const Twine &OriginalPath,
2395
+ const Twine &LookupPath , const Twine &OriginalPath,
2392
2396
const RedirectingFileSystem::LookupResult &Result) {
2393
2397
if (std::optional<StringRef> ExtRedirect = Result.getExternalRedirect ()) {
2394
- SmallString<256 > CanonicalRemappedPath ((*ExtRedirect).str ());
2395
- if (std::error_code EC = makeCanonical (CanonicalRemappedPath ))
2398
+ SmallString<256 > RemappedPath ((*ExtRedirect).str ());
2399
+ if (std::error_code EC = makeAbsolute (RemappedPath ))
2396
2400
return EC;
2397
2401
2398
- ErrorOr<Status> S = ExternalFS->status (CanonicalRemappedPath );
2402
+ ErrorOr<Status> S = ExternalFS->status (RemappedPath );
2399
2403
if (!S)
2400
2404
return S;
2401
2405
S = Status::copyWithNewName (*S, *ExtRedirect);
@@ -2405,13 +2409,13 @@ ErrorOr<Status> RedirectingFileSystem::status(
2405
2409
}
2406
2410
2407
2411
auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(Result.E );
2408
- return Status::copyWithNewName (DE->getStatus (), CanonicalPath );
2412
+ return Status::copyWithNewName (DE->getStatus (), LookupPath );
2409
2413
}
2410
2414
2411
2415
ErrorOr<Status>
2412
- RedirectingFileSystem::getExternalStatus (const Twine &CanonicalPath ,
2416
+ RedirectingFileSystem::getExternalStatus (const Twine &LookupPath ,
2413
2417
const Twine &OriginalPath) const {
2414
- auto Result = ExternalFS->status (CanonicalPath );
2418
+ auto Result = ExternalFS->status (LookupPath );
2415
2419
2416
2420
// The path has been mapped by some nested VFS, don't override it with the
2417
2421
// original path.
@@ -2421,65 +2425,63 @@ RedirectingFileSystem::getExternalStatus(const Twine &CanonicalPath,
2421
2425
}
2422
2426
2423
2427
ErrorOr<Status> RedirectingFileSystem::status (const Twine &OriginalPath) {
2424
- SmallString<256 > CanonicalPath ;
2425
- OriginalPath.toVector (CanonicalPath );
2428
+ SmallString<256 > Path ;
2429
+ OriginalPath.toVector (Path );
2426
2430
2427
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2431
+ if (std::error_code EC = makeAbsolute (Path ))
2428
2432
return EC;
2429
2433
2430
2434
if (Redirection == RedirectKind::Fallback) {
2431
2435
// Attempt to find the original file first, only falling back to the
2432
2436
// mapped file if that fails.
2433
- ErrorOr<Status> S = getExternalStatus (CanonicalPath , OriginalPath);
2437
+ ErrorOr<Status> S = getExternalStatus (Path , OriginalPath);
2434
2438
if (S)
2435
2439
return S;
2436
2440
}
2437
2441
2438
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2439
- lookupPath (CanonicalPath);
2442
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2440
2443
if (!Result) {
2441
2444
// Was not able to map file, fallthrough to using the original path if
2442
2445
// that was the specified redirection type.
2443
2446
if (Redirection == RedirectKind::Fallthrough &&
2444
2447
isFileNotFound (Result.getError ()))
2445
- return getExternalStatus (CanonicalPath , OriginalPath);
2448
+ return getExternalStatus (Path , OriginalPath);
2446
2449
return Result.getError ();
2447
2450
}
2448
2451
2449
- ErrorOr<Status> S = status (CanonicalPath , OriginalPath, *Result);
2452
+ ErrorOr<Status> S = status (Path , OriginalPath, *Result);
2450
2453
if (!S && Redirection == RedirectKind::Fallthrough &&
2451
2454
isFileNotFound (S.getError (), Result->E )) {
2452
2455
// Mapped the file but it wasn't found in the underlying filesystem,
2453
2456
// fallthrough to using the original path if that was the specified
2454
2457
// redirection type.
2455
- return getExternalStatus (CanonicalPath , OriginalPath);
2458
+ return getExternalStatus (Path , OriginalPath);
2456
2459
}
2457
2460
2458
2461
return S;
2459
2462
}
2460
2463
2461
2464
bool RedirectingFileSystem::exists (const Twine &OriginalPath) {
2462
- SmallString<256 > CanonicalPath ;
2463
- OriginalPath.toVector (CanonicalPath );
2465
+ SmallString<256 > Path ;
2466
+ OriginalPath.toVector (Path );
2464
2467
2465
- if (makeCanonical (CanonicalPath ))
2468
+ if (makeAbsolute (Path ))
2466
2469
return false ;
2467
2470
2468
2471
if (Redirection == RedirectKind::Fallback) {
2469
2472
// Attempt to find the original file first, only falling back to the
2470
2473
// mapped file if that fails.
2471
- if (ExternalFS->exists (CanonicalPath ))
2474
+ if (ExternalFS->exists (Path ))
2472
2475
return true ;
2473
2476
}
2474
2477
2475
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2476
- lookupPath (CanonicalPath);
2478
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2477
2479
if (!Result) {
2478
2480
// Was not able to map file, fallthrough to using the original path if
2479
2481
// that was the specified redirection type.
2480
2482
if (Redirection == RedirectKind::Fallthrough &&
2481
2483
isFileNotFound (Result.getError ()))
2482
- return ExternalFS->exists (CanonicalPath );
2484
+ return ExternalFS->exists (Path );
2483
2485
return false ;
2484
2486
}
2485
2487
@@ -2489,18 +2491,18 @@ bool RedirectingFileSystem::exists(const Twine &OriginalPath) {
2489
2491
return true ;
2490
2492
}
2491
2493
2492
- SmallString<256 > CanonicalRemappedPath ((*ExtRedirect).str ());
2493
- if (makeCanonical (CanonicalRemappedPath ))
2494
+ SmallString<256 > RemappedPath ((*ExtRedirect).str ());
2495
+ if (makeAbsolute (RemappedPath ))
2494
2496
return false ;
2495
2497
2496
- if (ExternalFS->exists (CanonicalRemappedPath ))
2498
+ if (ExternalFS->exists (RemappedPath ))
2497
2499
return true ;
2498
2500
2499
2501
if (Redirection == RedirectKind::Fallthrough) {
2500
2502
// Mapped the file but it wasn't found in the underlying filesystem,
2501
2503
// fallthrough to using the original path if that was the specified
2502
2504
// redirection type.
2503
- return ExternalFS->exists (CanonicalPath );
2505
+ return ExternalFS->exists (Path );
2504
2506
}
2505
2507
2506
2508
return false ;
@@ -2549,53 +2551,49 @@ File::getWithPath(ErrorOr<std::unique_ptr<File>> Result, const Twine &P) {
2549
2551
2550
2552
ErrorOr<std::unique_ptr<File>>
2551
2553
RedirectingFileSystem::openFileForRead (const Twine &OriginalPath) {
2552
- SmallString<256 > CanonicalPath ;
2553
- OriginalPath.toVector (CanonicalPath );
2554
+ SmallString<256 > Path ;
2555
+ OriginalPath.toVector (Path );
2554
2556
2555
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2557
+ if (std::error_code EC = makeAbsolute (Path ))
2556
2558
return EC;
2557
2559
2558
2560
if (Redirection == RedirectKind::Fallback) {
2559
2561
// Attempt to find the original file first, only falling back to the
2560
2562
// mapped file if that fails.
2561
- auto F = File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2562
- OriginalPath);
2563
+ auto F = File::getWithPath (ExternalFS->openFileForRead (Path), OriginalPath);
2563
2564
if (F)
2564
2565
return F;
2565
2566
}
2566
2567
2567
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2568
- lookupPath (CanonicalPath);
2568
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2569
2569
if (!Result) {
2570
2570
// Was not able to map file, fallthrough to using the original path if
2571
2571
// that was the specified redirection type.
2572
2572
if (Redirection == RedirectKind::Fallthrough &&
2573
2573
isFileNotFound (Result.getError ()))
2574
- return File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2575
- OriginalPath);
2574
+ return File::getWithPath (ExternalFS->openFileForRead (Path), OriginalPath);
2576
2575
return Result.getError ();
2577
2576
}
2578
2577
2579
2578
if (!Result->getExternalRedirect ()) // FIXME: errc::not_a_file?
2580
2579
return make_error_code (llvm::errc::invalid_argument);
2581
2580
2582
2581
StringRef ExtRedirect = *Result->getExternalRedirect ();
2583
- SmallString<256 > CanonicalRemappedPath (ExtRedirect.str ());
2584
- if (std::error_code EC = makeCanonical (CanonicalRemappedPath ))
2582
+ SmallString<256 > RemappedPath (ExtRedirect.str ());
2583
+ if (std::error_code EC = makeAbsolute (RemappedPath ))
2585
2584
return EC;
2586
2585
2587
2586
auto *RE = cast<RedirectingFileSystem::RemapEntry>(Result->E );
2588
2587
2589
- auto ExternalFile = File::getWithPath (
2590
- ExternalFS->openFileForRead (CanonicalRemappedPath ), ExtRedirect);
2588
+ auto ExternalFile =
2589
+ File::getWithPath ( ExternalFS->openFileForRead (RemappedPath ), ExtRedirect);
2591
2590
if (!ExternalFile) {
2592
2591
if (Redirection == RedirectKind::Fallthrough &&
2593
2592
isFileNotFound (ExternalFile.getError (), Result->E )) {
2594
2593
// Mapped the file but it wasn't found in the underlying filesystem,
2595
2594
// fallthrough to using the original path if that was the specified
2596
2595
// redirection type.
2597
- return File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2598
- OriginalPath);
2596
+ return File::getWithPath (ExternalFS->openFileForRead (Path), OriginalPath);
2599
2597
}
2600
2598
return ExternalFile;
2601
2599
}
@@ -2615,28 +2613,27 @@ RedirectingFileSystem::openFileForRead(const Twine &OriginalPath) {
2615
2613
std::error_code
2616
2614
RedirectingFileSystem::getRealPath (const Twine &OriginalPath,
2617
2615
SmallVectorImpl<char > &Output) const {
2618
- SmallString<256 > CanonicalPath ;
2619
- OriginalPath.toVector (CanonicalPath );
2616
+ SmallString<256 > Path ;
2617
+ OriginalPath.toVector (Path );
2620
2618
2621
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2619
+ if (std::error_code EC = makeAbsolute (Path ))
2622
2620
return EC;
2623
2621
2624
2622
if (Redirection == RedirectKind::Fallback) {
2625
2623
// Attempt to find the original file first, only falling back to the
2626
2624
// mapped file if that fails.
2627
- std::error_code EC = ExternalFS->getRealPath (CanonicalPath , Output);
2625
+ std::error_code EC = ExternalFS->getRealPath (Path , Output);
2628
2626
if (!EC)
2629
2627
return EC;
2630
2628
}
2631
2629
2632
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2633
- lookupPath (CanonicalPath);
2630
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2634
2631
if (!Result) {
2635
2632
// Was not able to map file, fallthrough to using the original path if
2636
2633
// that was the specified redirection type.
2637
2634
if (Redirection == RedirectKind::Fallthrough &&
2638
2635
isFileNotFound (Result.getError ()))
2639
- return ExternalFS->getRealPath (CanonicalPath , Output);
2636
+ return ExternalFS->getRealPath (Path , Output);
2640
2637
return Result.getError ();
2641
2638
}
2642
2639
@@ -2649,7 +2646,7 @@ RedirectingFileSystem::getRealPath(const Twine &OriginalPath,
2649
2646
// Mapped the file but it wasn't found in the underlying filesystem,
2650
2647
// fallthrough to using the original path if that was the specified
2651
2648
// redirection type.
2652
- return ExternalFS->getRealPath (CanonicalPath , Output);
2649
+ return ExternalFS->getRealPath (Path , Output);
2653
2650
}
2654
2651
return P;
2655
2652
}
0 commit comments