Lines Matching +full:overlay +full:- +full:relative
1 //===- VirtualFileSystem.cpp - Virtual File System Layer ------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
24 #include "llvm/Config/llvm-config.h"
125 return (*F)->getBuffer(Name, FileSize, RequiresNullTerminator, IsVolatile);
151 return Status && Status->exists();
161 return StatusA->equivalent(*StatusB);
183 //===-----------------------------------------------------------------------===/
185 //===-----------------------------------------------------------------------===/
265 /// This would enable the use of openat()-style functions on some platforms.
303 sys::fs::make_absolute(WD->get().Resolved, Storage);
350 return std::string(WD->get().Specified);
352 return WD->getError();
416 CurrentEntry = directory_entry(Iter->path(), Iter->type());
424 : directory_entry(Iter->path(), Iter->type());
438 //===-----------------------------------------------------------------------===/
440 //===-----------------------------------------------------------------------===/
450 FS->setCurrentWorkingDirectory(getCurrentWorkingDirectory().get());
456 ErrorOr<Status> Status = (*I)->status(Path);
466 if ((*I)->exists(Path))
476 auto Result = (*I)->openFileForRead(Path);
486 return FSList.front()->getCurrentWorkingDirectory();
492 if (std::error_code EC = FS->setCurrentWorkingDirectory(Path))
499 if (FS->exists(Path))
500 return FS->isLocal(Path, Result);
507 if (FS->exists(Path))
508 return FS->getRealPath(Path, Output);
515 FS->visitChildFileSystems(Callback);
529 FS->print(OS, Type, IndentLevel + 1);
593 directory_iterator Iter = FS->dir_begin(Dir, FEC);
680 return N->getKind() == IME_File;
699 return std::string(Indent, ' ') + "HardLink to -> " +
704 return N->getKind() == IME_HardLink;
718 return std::string(Indent, ' ') + "SymbolicLink to -> " + TargetPath;
728 return N->getKind() == IME_SymbolicLink;
754 Buf->getBuffer(), Buf->getBufferIdentifier(), RequiresNullTerminator);
783 return I->second.get();
788 return Entries.emplace(Name, std::move(Child)).first->second.get();
800 Result += Entry.second->toString(Indent + 2);
805 return N->getKind() == IME_Directory;
811 // The UniqueID of in-memory files is derived from path and content.
812 // This avoids difficulties in creating exactly equivalent in-memory FSes,
832 : getFileID(DirUID, Name, Buffer ? Buffer->getBuffer() : "");
835 Group, Buffer ? Buffer->getBufferSize() : 0, Type, Perms);
849 return Root->toString(/*Indent=*/0);
862 // Fix up relative paths. This just prepends the current working directory.
889 detail::InMemoryNode *Node = Dir->getChild(Name);
893 StringRef(Path.str().begin(), Name.end() - Path.str().begin()),
894 getDirectoryID(Dir->getUniqueID(), Name),
897 Dir = cast<detail::InMemoryDirectory>(Dir->addChild(
906 detail::InMemoryNode *Node = Dir->getChild(Name);
908 Dir->addChild(Name,
909 MakeNode({Dir->getUniqueID(), Path, Name, ModificationTime,
923 return Link->getResolvedFile().getBuffer()->getBuffer() ==
924 Buffer->getBuffer();
926 return cast<detail::InMemoryFile>(Node)->getBuffer()->getBuffer() ==
927 Buffer->getBuffer();
939 -> std::unique_ptr<detail::InMemoryNode> {
957 -> std::unique_ptr<detail::InMemoryNode> {
972 // Fix up relative paths. This just prepends the current working directory.
986 detail::InMemoryNode *Node = Dir->getChild(*I);
1000 SmallString<128> TargetPath = Symlink->getTargetPath();
1031 return detail::NamedNodeOrError(Path, &File->getResolvedFile());
1045 // implementation-defined in POSIX.
1083 return (*Node)->getStatus(Path);
1093 // When we have a file provide a heap-allocated wrapper for the memory buffer
1113 llvm::sys::path::append(Path, I->second->getFileName());
1115 switch (I->second->getKind()) {
1125 FS->lookupNode(Path, /*FollowFinalSymlink=*/true)) {
1127 Type = (*SymlinkTarget)->getStatus(Path).getType();
1177 // Fix up relative paths. This just prepends the current working directory.
1193 if (!CWD || CWD->empty())
1216 //===-----------------------------------------------------------------------===/
1218 //===-----------------------------------------------------------------------===/
1227 if (n != static_cast<size_t>(-1))
1261 ExternalFS->getCurrentWorkingDirectory()) {
1279 llvm::sys::path::append(PathStr, (*Current)->getName());
1281 switch ((*Current)->getKind()) {
1330 StringRef ExternalPath = ExternalIter->path();
1337 CurrentEntry = directory_entry(std::string(NewPath), ExternalIter->type());
1379 return ExternalFS->isLocal(Path, Result);
1451 return ExternalFS->dir_begin(Path, EC);
1461 isFileNotFound(S.getError(), Result->E))
1462 return ExternalFS->dir_begin(Dir, EC);
1468 if (!S->isDirectory()) {
1477 if (auto ExtRedirect = Result->getExternalRedirect()) {
1478 auto RE = cast<RedirectingFileSystem::RemapEntry>(Result->E);
1479 RedirectIter = ExternalFS->dir_begin(*ExtRedirect, RedirectEC);
1481 if (!RE->useExternalName(UseExternalNames)) {
1488 auto DE = cast<DirectoryEntry>(Result->E);
1491 Path, DE->contents_begin(), DE->contents_end(), RedirectEC));
1508 directory_iterator ExternalIter = ExternalFS->dir_begin(Path, ExternalEC);
1563 R.push_back(Root->getName());
1580 ExternalFS->print(OS, Type == PrintType::Contents ? PrintType::Summary : Type,
1588 OS << "'" << E->getName() << "'";
1590 switch (E->getKind()) {
1596 llvm::make_range(DE->contents_begin(), DE->contents_end()))
1603 OS << " -> '" << RE->getExternalContentsPath() << "'";
1604 switch (RE->getUseName()) {
1623 ExternalFS->visitChildFileSystems(Callback);
1642 Result = S->getValue(Storage);
1679 } else if (Value.equals_insensitive("redirect-only")) {
1693 } else if (Value.equals_insensitive("overlay-dir")) {
1716 KeyStatus &S = It->second;
1741 for (const auto &Root : FS->Roots) {
1742 if (Name == Root->getName()) {
1750 llvm::make_range(DE->contents_begin(), DE->contents_end())) {
1753 if (DirContent && Name == Content->getName())
1765 if (!ParentEntry) { // Add a new root to the overlay
1766 FS->Roots.push_back(std::move(E));
1767 ParentEntry = FS->Roots.back().get();
1772 DE->addContent(std::move(E));
1773 return DE->getLastContent();
1780 StringRef Name = SrcE->getName();
1781 switch (SrcE->getKind()) {
1790 llvm::make_range(DE->contents_begin(), DE->contents_end()))
1798 DE->addContent(
1800 Name, DR->getExternalContentsPath(), DR->getUseName()));
1807 DE->addContent(std::make_unique<RedirectingFileSystem::FileEntry>(
1808 Name, FE->getExternalContentsPath(), FE->getUseName()));
1826 KeyStatusPair("external-contents", false),
1827 KeyStatusPair("use-external-name", false),
1868 else if (Value == "directory-remap")
1877 "entry already has 'contents' or 'external-contents'");
1895 } else if (Key == "external-contents") {
1898 "entry already has 'contents' or 'external-contents'");
1906 if (FS->IsRelativeOverlay) {
1907 FullPath = FS->getOverlayFileDir();
1919 } else if (Key == "use-external-name") {
1935 error(N, "missing key 'contents' or 'external-contents'");
1944 error(N, "'use-external-name' is not supported for 'directory' entries");
1950 error(N, "'contents' is not supported for 'directory-remap' entries");
1964 // Relative VFS root entries are made absolute to either the overlay
1968 if (FS->RootRelative ==
1970 StringRef FullPath = FS->getOverlayFileDir();
1971 assert(!FullPath.empty() && "Overlay file directory must exist");
1972 EC = FS->makeAbsolute(FullPath, Name);
1981 "entry with relative path at the root level is not discoverable");
2001 Trimmed = Trimmed.slice(0, Trimmed.size() - 1);
2055 KeyStatusPair("case-sensitive", false),
2056 KeyStatusPair("use-external-names", false),
2057 KeyStatusPair("root-relative", false),
2058 KeyStatusPair("overlay-relative", false),
2060 KeyStatusPair("redirecting-with", false),
2109 } else if (Key == "case-sensitive") {
2110 if (!parseScalarBool(I.getValue(), FS->CaseSensitive))
2112 } else if (Key == "overlay-relative") {
2113 if (!parseScalarBool(I.getValue(), FS->IsRelativeOverlay))
2115 } else if (Key == "use-external-names") {
2116 if (!parseScalarBool(I.getValue(), FS->UseExternalNames))
2119 if (Keys["redirecting-with"].Seen) {
2121 "'fallthrough' and 'redirecting-with' are mutually exclusive");
2130 FS->Redirection = RedirectingFileSystem::RedirectKind::Fallthrough;
2132 FS->Redirection = RedirectingFileSystem::RedirectKind::RedirectOnly;
2134 } else if (Key == "redirecting-with") {
2137 "'fallthrough' and 'redirecting-with' are mutually exclusive");
2142 FS->Redirection = *Kind;
2147 } else if (Key == "root-relative") {
2149 FS->RootRelative = *Kind;
2151 error(I.getValue(), "expected valid root-relative kind");
2181 yaml::Stream Stream(Buffer->getMemBufferRef(), SM);
2185 yaml::Node *Root = DI->getRoot();
2197 // Use the YAML path from -ivfsoverlay to compute the dir to be prefixed
2198 // to each 'external-contents' path.
2201 // -ivfsoverlay dummy.cache/vfs/vfs.yaml
2203 // FS->OverlayFileDir => /<absolute_path_to>/dummy.cache/vfs
2207 assert(!EC && "Overlay dir final path must be absolute");
2209 FS->setOverlayFileDir(OverlayAbsDir);
2223 FS->UseExternalNames = UseExternalNames;
2264 cast<RedirectingFileSystem::DirectoryEntry>(Parent)->addContent(
2279 SmallString<256> Redirect(DRE->getExternalContentsPath());
2281 getExistingStyle(DRE->getExternalContentsPath()));
2290 llvm::sys::path::append(Result, Parent->getName());
2291 llvm::sys::path::append(Result, E->getName());
2324 if (UsageTrackingActive && Result && isa<RemapEntry>(Result->E))
2327 Result->Parents = std::move(Entries);
2340 !isTraversalComponent(From->getName()) &&
2343 StringRef FromName = From->getName();
2366 llvm::make_range(DE->contents_begin(), DE->contents_end())) {
2402 ErrorOr<Status> S = ExternalFS->status(RemappedPath);
2408 RE->useExternalName(UseExternalNames), *S);
2412 return Status::copyWithNewName(DE->getStatus(), LookupPath);
2418 auto Result = ExternalFS->status(LookupPath);
2422 if (!Result || Result->ExposesExternalVFSPath)
2454 isFileNotFound(S.getError(), Result->E)) {
2474 if (ExternalFS->exists(Path))
2484 return ExternalFS->exists(Path);
2488 std::optional<StringRef> ExtRedirect = Result->getExternalRedirect();
2490 assert(isa<RedirectingFileSystem::DirectoryEntry>(Result->E));
2498 if (ExternalFS->exists(RemappedPath))
2505 return ExternalFS->exists(Path);
2527 return InnerFile->getBuffer(Name, FileSize, RequiresNullTerminator,
2531 std::error_code close() override { return InnerFile->close(); }
2540 // See \c getRedirectedFileStatus - don't update path if it's exposing an
2542 if (!Result || (*Result)->status()->ExposesExternalVFSPath)
2546 auto Name = F->get()->getName();
2548 F->get()->setPath(P);
2563 auto F = File::getWithPath(ExternalFS->openFileForRead(Path), OriginalPath);
2574 return File::getWithPath(ExternalFS->openFileForRead(Path), OriginalPath);
2578 if (!Result->getExternalRedirect()) // FIXME: errc::not_a_file?
2581 StringRef ExtRedirect = *Result->getExternalRedirect();
2586 auto *RE = cast<RedirectingFileSystem::RemapEntry>(Result->E);
2589 File::getWithPath(ExternalFS->openFileForRead(RemappedPath), ExtRedirect);
2592 isFileNotFound(ExternalFile.getError(), Result->E)) {
2596 return File::getWithPath(ExternalFS->openFileForRead(Path), OriginalPath);
2601 auto ExternalStatus = (*ExternalFile)->status();
2608 OriginalPath, RE->useExternalName(UseExternalNames), *ExternalStatus);
2625 std::error_code EC = ExternalFS->getRealPath(Path, Output);
2636 return ExternalFS->getRealPath(Path, Output);
2642 if (auto ExtRedirect = Result->getExternalRedirect()) {
2643 auto P = ExternalFS->getRealPath(*ExtRedirect, Output);
2645 isFileNotFound(P, Result->E)) {
2649 return ExternalFS->getRealPath(Path, Output);
2657 Result->getPath(Output);
2676 auto Kind = SrcE->getKind();
2681 llvm::make_range(DE->contents_begin(), DE->contents_end())) {
2682 Path.push_back(SubEntry->getName());
2696 YAMLVFSEntry(VPath.c_str(), DR->getExternalContentsPath()));
2706 Entries.push_back(YAMLVFSEntry(VPath.c_str(), FE->getExternalContentsPath()));
2721 VFS->lookupPath("/");
2726 getVFSEntries(RootResult->E, Components, CollectedEntries);
2823 OS.indent(Indent + 2) << "'external-contents': \""
2838 OS << " 'case-sensitive': '" << (*IsCaseSensitive ? "true" : "false")
2841 OS << " 'use-external-names': '" << (*UseExternalNames ? "true" : "false")
2846 OS << " 'overlay-relative': '" << (UseOverlayRelative ? "true" : "false")
2861 "Overlay dir must be contained in RPath");
2894 "Overlay dir must be contained in RPath");
2926 directory_iterator I = FS->dir_begin(Path, EC);
2929 State->Stack.push_back(I);
2935 assert(FS && State && !State->Stack.empty() && "incrementing past end");
2936 assert(!State->Stack.back()->path().empty() && "non-canonical end iterator");
2939 if (State->HasNoPushRequest)
2940 State->HasNoPushRequest = false;
2942 if (State->Stack.back()->type() == sys::fs::file_type::directory_file) {
2944 FS->dir_begin(State->Stack.back()->path(), EC);
2946 State->Stack.push_back(I);
2952 while (!State->Stack.empty() && State->Stack.back().increment(EC) == End)
2953 State->Stack.pop_back();
2955 if (State->Stack.empty())