|
22 | 22 | #include "llvm/ADT/Twine.h" |
23 | 23 | #include "llvm/ADT/iterator_range.h" |
24 | 24 | #include "llvm/CAS/CASReference.h" |
| 25 | +#include "llvm/CAS/CASFileSystem.h" |
25 | 26 | #include "llvm/Config/llvm-config.h" |
26 | 27 | #include "llvm/Support/Casting.h" |
27 | 28 | #include "llvm/Support/Chrono.h" |
@@ -2534,6 +2535,33 @@ class FileWithFixedStatus : public File { |
2534 | 2535 | void setPath(const Twine &Path) override { S = S.copyWithNewName(S, Path); } |
2535 | 2536 | }; |
2536 | 2537 |
|
| 2538 | + |
| 2539 | +class CASFileWithFixedStatus : public cas::CASBackedFile { |
| 2540 | + std::unique_ptr<cas::CASBackedFile> InnerFile; |
| 2541 | + Status S; |
| 2542 | + |
| 2543 | +public: |
| 2544 | + CASFileWithFixedStatus(std::unique_ptr<CASBackedFile> InnerFile, Status S) |
| 2545 | + : InnerFile(std::move(InnerFile)), S(std::move(S)) {} |
| 2546 | + |
| 2547 | + ErrorOr<Status> status() override { return S; } |
| 2548 | + ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> |
| 2549 | + |
| 2550 | + getBuffer(const Twine &Name, int64_t FileSize, bool RequiresNullTerminator, |
| 2551 | + bool IsVolatile) override { |
| 2552 | + return InnerFile->getBuffer(Name, FileSize, RequiresNullTerminator, |
| 2553 | + IsVolatile); |
| 2554 | + } |
| 2555 | + |
| 2556 | + std::error_code close() override { return InnerFile->close(); } |
| 2557 | + |
| 2558 | + void setPath(const Twine &Path) override { S = S.copyWithNewName(S, Path); } |
| 2559 | + |
| 2560 | + cas::ObjectRef getObjectRefForContent() override { |
| 2561 | + return InnerFile->getObjectRefForContent(); |
| 2562 | + } |
| 2563 | +}; |
| 2564 | + |
2537 | 2565 | } // namespace |
2538 | 2566 |
|
2539 | 2567 | ErrorOr<std::unique_ptr<File>> |
@@ -2607,6 +2635,12 @@ RedirectingFileSystem::openFileForRead(const Twine &OriginalPath) { |
2607 | 2635 | // replace the underlying path if the external name is being used. |
2608 | 2636 | Status S = getRedirectedFileStatus( |
2609 | 2637 | OriginalPath, RE->useExternalName(UseExternalNames), *ExternalStatus); |
| 2638 | + |
| 2639 | + if (std::unique_ptr<cas::CASBackedFile> CASFile = |
| 2640 | + dyn_cast<cas::CASBackedFile>(*ExternalFile)) { |
| 2641 | + return std::unique_ptr<File>( |
| 2642 | + std::make_unique<CASFileWithFixedStatus>(std::move(CASFile), S)); |
| 2643 | + } |
2610 | 2644 | return std::unique_ptr<File>( |
2611 | 2645 | std::make_unique<FileWithFixedStatus>(std::move(*ExternalFile), S)); |
2612 | 2646 | } |
@@ -2991,3 +3025,7 @@ const char ProxyFileSystem::ID = 0; |
2991 | 3025 | const char InMemoryFileSystem::ID = 0; |
2992 | 3026 | const char RedirectingFileSystem::ID = 0; |
2993 | 3027 | const char TracingFileSystem::ID = 0; |
| 3028 | + |
| 3029 | +// FIXME: Temporarily put the CASBackedFile::ID in Support library to workaround |
| 3030 | +// the layer issue that `dyn_cast` check for the type needs to happen here. |
| 3031 | +const char cas::CASBackedFile::ID = 0; |
0 commit comments