llvm.org GIT mirror llvm / 33443e8
Extend virtual file system with `isLocal` method Expose the `llvm::sys::fs::is_local` function through the VFS. Differential revision: https://reviews.llvm.org/D54127 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346372 91177308-0d34-0410-b5e6-96231b3b80d8 Jonas Devlieghere 10 months ago
3 changed file(s) with 41 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
278278 /// Check whether a file exists. Provided for convenience.
279279 bool exists(const Twine &Path);
280280
281 /// Is the file mounted on a local filesystem?
282 virtual std::error_code isLocal(const Twine &Path, bool &Result);
283
281284 /// Make \a Path an absolute path.
282285 ///
283286 /// Makes \a Path absolute using the current directory if it is not already.
325328 directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
326329 llvm::ErrorOr getCurrentWorkingDirectory() const override;
327330 std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
331 std::error_code isLocal(const Twine &Path, bool &Result) override;
328332 std::error_code getRealPath(const Twine &Path,
329333 SmallVectorImpl &Output) const override;
330334
462466 /// system.
463467 std::error_code getRealPath(const Twine &Path,
464468 SmallVectorImpl &Output) const override;
465
469 std::error_code isLocal(const Twine &Path, bool &Result) override;
466470 std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
467471 };
468472
135135 return errc::operation_not_permitted;
136136 }
137137
138 std::error_code FileSystem::isLocal(const Twine &Path, bool &Result) {
139 return errc::operation_not_permitted;
140 }
141
138142 bool FileSystem::exists(const Twine &Path) {
139143 auto Status = status(Path);
140144 return Status && Status->exists();
232236
233237 llvm::ErrorOr getCurrentWorkingDirectory() const override;
234238 std::error_code setCurrentWorkingDirectory(const Twine &Path) override;
239 std::error_code isLocal(const Twine &Path, bool &Result) override;
235240 std::error_code getRealPath(const Twine &Path,
236241 SmallVectorImpl &Output) const override;
237242
287292 return std::error_code();
288293 }
289294
295 std::error_code RealFileSystem::isLocal(const Twine &Path, bool &Result) {
296 return llvm::sys::fs::is_local(Path, Result);
297 }
298
290299 std::error_code
291300 RealFileSystem::getRealPath(const Twine &Path,
292301 SmallVectorImpl &Output) const {
374383 if (std::error_code EC = FS->setCurrentWorkingDirectory(Path))
375384 return EC;
376385 return {};
386 }
387
388 std::error_code OverlayFileSystem::isLocal(const Twine &Path, bool &Result) {
389 for (auto &FS : FSList)
390 if (FS->exists(Path))
391 return FS->isLocal(Path, Result);
392 return errc::no_such_file_or_directory;
377393 }
378394
379395 std::error_code
909925 if (auto EC = makeAbsolute(Output))
910926 return EC;
911927 llvm::sys::path::remove_dots(Output, /*remove_dot_dot=*/true);
928 return {};
929 }
930
931 std::error_code InMemoryFileSystem::isLocal(const Twine &Path, bool &Result) {
932 Result = false;
912933 return {};
913934 }
914935
11691190 return ExternalFS->setCurrentWorkingDirectory(Path);
11701191 }
11711192
1193 std::error_code isLocal(const Twine &Path, bool &Result) override {
1194 return ExternalFS->isLocal(Path, Result);
1195 }
1196
11721197 directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override {
11731198 ErrorOr E = lookupPath(Dir);
11741199 if (!E) {
884884 getPosixPath(NormalizedFS.getCurrentWorkingDirectory().get()));
885885 }
886886
887 TEST_F(InMemoryFileSystemTest, IsLocal) {
888 FS.setCurrentWorkingDirectory("/b");
889 FS.addFile("c", 0, MemoryBuffer::getMemBuffer(""));
890
891 std::error_code EC;
892 bool IsLocal = true;
893 EC = FS.isLocal("c", IsLocal);
894 ASSERT_FALSE(EC);
895 ASSERT_FALSE(IsLocal);
896 }
897
887898 #if !defined(_WIN32)
888899 TEST_F(InMemoryFileSystemTest, GetRealPath) {
889900 SmallString<16> Path;