@@ -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 (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 =
@@ -2387,14 +2391,14 @@ static Status getRedirectedFileStatus(const Twine &OriginalPath,
2387
2391
}
2388
2392
2389
2393
ErrorOr<Status> RedirectingFileSystem::status (
2390
- const Twine &CanonicalPath , const Twine &OriginalPath,
2394
+ const Twine &LookupPath , const Twine &OriginalPath,
2391
2395
const RedirectingFileSystem::LookupResult &Result) {
2392
2396
if (std::optional<StringRef> ExtRedirect = Result.getExternalRedirect ()) {
2393
- SmallString<256 > CanonicalRemappedPath ((*ExtRedirect).str ());
2394
- if (std::error_code EC = makeCanonical (CanonicalRemappedPath ))
2397
+ SmallString<256 > RemappedPath ((*ExtRedirect).str ());
2398
+ if (std::error_code EC = makeAbsolute (RemappedPath ))
2395
2399
return EC;
2396
2400
2397
- ErrorOr<Status> S = ExternalFS->status (CanonicalRemappedPath );
2401
+ ErrorOr<Status> S = ExternalFS->status (RemappedPath );
2398
2402
if (!S)
2399
2403
return S;
2400
2404
S = Status::copyWithNewName (*S, *ExtRedirect);
@@ -2404,13 +2408,13 @@ ErrorOr<Status> RedirectingFileSystem::status(
2404
2408
}
2405
2409
2406
2410
auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(Result.E );
2407
- return Status::copyWithNewName (DE->getStatus (), CanonicalPath );
2411
+ return Status::copyWithNewName (DE->getStatus (), LookupPath );
2408
2412
}
2409
2413
2410
2414
ErrorOr<Status>
2411
- RedirectingFileSystem::getExternalStatus (const Twine &CanonicalPath ,
2415
+ RedirectingFileSystem::getExternalStatus (const Twine &LookupPath ,
2412
2416
const Twine &OriginalPath) const {
2413
- auto Result = ExternalFS->status (CanonicalPath );
2417
+ auto Result = ExternalFS->status (LookupPath );
2414
2418
2415
2419
// The path has been mapped by some nested VFS, don't override it with the
2416
2420
// original path.
@@ -2420,38 +2424,37 @@ RedirectingFileSystem::getExternalStatus(const Twine &CanonicalPath,
2420
2424
}
2421
2425
2422
2426
ErrorOr<Status> RedirectingFileSystem::status (const Twine &OriginalPath) {
2423
- SmallString<256 > CanonicalPath ;
2424
- OriginalPath.toVector (CanonicalPath );
2427
+ SmallString<256 > Path ;
2428
+ OriginalPath.toVector (Path );
2425
2429
2426
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2430
+ if (std::error_code EC = makeAbsolute (Path ))
2427
2431
return EC;
2428
2432
2429
2433
if (Redirection == RedirectKind::Fallback) {
2430
2434
// Attempt to find the original file first, only falling back to the
2431
2435
// mapped file if that fails.
2432
- ErrorOr<Status> S = getExternalStatus (CanonicalPath , OriginalPath);
2436
+ ErrorOr<Status> S = getExternalStatus (Path , OriginalPath);
2433
2437
if (S)
2434
2438
return S;
2435
2439
}
2436
2440
2437
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2438
- lookupPath (CanonicalPath);
2441
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2439
2442
if (!Result) {
2440
2443
// Was not able to map file, fallthrough to using the original path if
2441
2444
// that was the specified redirection type.
2442
2445
if (Redirection == RedirectKind::Fallthrough &&
2443
2446
isFileNotFound (Result.getError ()))
2444
- return getExternalStatus (CanonicalPath , OriginalPath);
2447
+ return getExternalStatus (Path , OriginalPath);
2445
2448
return Result.getError ();
2446
2449
}
2447
2450
2448
- ErrorOr<Status> S = status (CanonicalPath , OriginalPath, *Result);
2451
+ ErrorOr<Status> S = status (Path , OriginalPath, *Result);
2449
2452
if (!S && Redirection == RedirectKind::Fallthrough &&
2450
2453
isFileNotFound (S.getError (), Result->E )) {
2451
2454
// Mapped the file but it wasn't found in the underlying filesystem,
2452
2455
// fallthrough to using the original path if that was the specified
2453
2456
// redirection type.
2454
- return getExternalStatus (CanonicalPath , OriginalPath);
2457
+ return getExternalStatus (Path , OriginalPath);
2455
2458
}
2456
2459
2457
2460
return S;
@@ -2548,53 +2551,49 @@ File::getWithPath(ErrorOr<std::unique_ptr<File>> Result, const Twine &P) {
2548
2551
2549
2552
ErrorOr<std::unique_ptr<File>>
2550
2553
RedirectingFileSystem::openFileForRead (const Twine &OriginalPath) {
2551
- SmallString<256 > CanonicalPath ;
2552
- OriginalPath.toVector (CanonicalPath );
2554
+ SmallString<256 > Path ;
2555
+ OriginalPath.toVector (Path );
2553
2556
2554
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2557
+ if (std::error_code EC = makeAbsolute (Path ))
2555
2558
return EC;
2556
2559
2557
2560
if (Redirection == RedirectKind::Fallback) {
2558
2561
// Attempt to find the original file first, only falling back to the
2559
2562
// mapped file if that fails.
2560
- auto F = File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2561
- OriginalPath);
2563
+ auto F = File::getWithPath (ExternalFS->openFileForRead (Path), OriginalPath);
2562
2564
if (F)
2563
2565
return F;
2564
2566
}
2565
2567
2566
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2567
- lookupPath (CanonicalPath);
2568
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2568
2569
if (!Result) {
2569
2570
// Was not able to map file, fallthrough to using the original path if
2570
2571
// that was the specified redirection type.
2571
2572
if (Redirection == RedirectKind::Fallthrough &&
2572
2573
isFileNotFound (Result.getError ()))
2573
- return File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2574
- OriginalPath);
2574
+ return File::getWithPath (ExternalFS->openFileForRead (Path), OriginalPath);
2575
2575
return Result.getError ();
2576
2576
}
2577
2577
2578
2578
if (!Result->getExternalRedirect ()) // FIXME: errc::not_a_file?
2579
2579
return make_error_code (llvm::errc::invalid_argument);
2580
2580
2581
2581
StringRef ExtRedirect = *Result->getExternalRedirect ();
2582
- SmallString<256 > CanonicalRemappedPath (ExtRedirect.str ());
2583
- if (std::error_code EC = makeCanonical (CanonicalRemappedPath ))
2582
+ SmallString<256 > RemappedPath (ExtRedirect.str ());
2583
+ if (std::error_code EC = makeAbsolute (RemappedPath ))
2584
2584
return EC;
2585
2585
2586
2586
auto *RE = cast<RedirectingFileSystem::RemapEntry>(Result->E );
2587
2587
2588
- auto ExternalFile = File::getWithPath (
2589
- ExternalFS->openFileForRead (CanonicalRemappedPath ), ExtRedirect);
2588
+ auto ExternalFile =
2589
+ File::getWithPath ( ExternalFS->openFileForRead (RemappedPath ), ExtRedirect);
2590
2590
if (!ExternalFile) {
2591
2591
if (Redirection == RedirectKind::Fallthrough &&
2592
2592
isFileNotFound (ExternalFile.getError (), Result->E )) {
2593
2593
// Mapped the file but it wasn't found in the underlying filesystem,
2594
2594
// fallthrough to using the original path if that was the specified
2595
2595
// redirection type.
2596
- return File::getWithPath (ExternalFS->openFileForRead (CanonicalPath),
2597
- OriginalPath);
2596
+ return File::getWithPath (ExternalFS->openFileForRead (Path), OriginalPath);
2598
2597
}
2599
2598
return ExternalFile;
2600
2599
}
@@ -2614,28 +2613,27 @@ RedirectingFileSystem::openFileForRead(const Twine &OriginalPath) {
2614
2613
std::error_code
2615
2614
RedirectingFileSystem::getRealPath (const Twine &OriginalPath,
2616
2615
SmallVectorImpl<char > &Output) const {
2617
- SmallString<256 > CanonicalPath ;
2618
- OriginalPath.toVector (CanonicalPath );
2616
+ SmallString<256 > Path ;
2617
+ OriginalPath.toVector (Path );
2619
2618
2620
- if (std::error_code EC = makeCanonical (CanonicalPath ))
2619
+ if (std::error_code EC = makeAbsolute (Path ))
2621
2620
return EC;
2622
2621
2623
2622
if (Redirection == RedirectKind::Fallback) {
2624
2623
// Attempt to find the original file first, only falling back to the
2625
2624
// mapped file if that fails.
2626
- std::error_code EC = ExternalFS->getRealPath (CanonicalPath , Output);
2625
+ std::error_code EC = ExternalFS->getRealPath (Path , Output);
2627
2626
if (!EC)
2628
2627
return EC;
2629
2628
}
2630
2629
2631
- ErrorOr<RedirectingFileSystem::LookupResult> Result =
2632
- lookupPath (CanonicalPath);
2630
+ ErrorOr<RedirectingFileSystem::LookupResult> Result = lookupPath (Path);
2633
2631
if (!Result) {
2634
2632
// Was not able to map file, fallthrough to using the original path if
2635
2633
// that was the specified redirection type.
2636
2634
if (Redirection == RedirectKind::Fallthrough &&
2637
2635
isFileNotFound (Result.getError ()))
2638
- return ExternalFS->getRealPath (CanonicalPath , Output);
2636
+ return ExternalFS->getRealPath (Path , Output);
2639
2637
return Result.getError ();
2640
2638
}
2641
2639
@@ -2648,7 +2646,7 @@ RedirectingFileSystem::getRealPath(const Twine &OriginalPath,
2648
2646
// Mapped the file but it wasn't found in the underlying filesystem,
2649
2647
// fallthrough to using the original path if that was the specified
2650
2648
// redirection type.
2651
- return ExternalFS->getRealPath (CanonicalPath , Output);
2649
+ return ExternalFS->getRealPath (Path , Output);
2652
2650
}
2653
2651
return P;
2654
2652
}
0 commit comments