Lines Matching +full:de +full:- +full:assert

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"
94 assert(isStatusKnown() && Other.isStatusKnown()); in equivalent()
125 return (*F)->getBuffer(Name, FileSize, RequiresNullTerminator, IsVolatile); in getBufferForFile()
151 return Status && Status->exists(); in exists()
161 return StatusA->equivalent(*StatusB); in equivalent()
183 //===-----------------------------------------------------------------------===/
185 //===-----------------------------------------------------------------------===/
201 assert(FD != kInvalidFile && "Invalid or inactive file descriptor");
222 assert(FD != kInvalidFile && "cannot stat closed file"); in status()
239 assert(FD != kInvalidFile && "cannot get buffer for closed file"); in getBuffer()
265 /// This would enable the use of openat()-style functions on some platforms.
301 sys::fs::make_absolute(WD->get().Resolved, Storage); in adjustPath()
338 return std::string(WD->get().Specified); in getCurrentWorkingDirectory()
340 return WD->getError(); in getCurrentWorkingDirectory()
404 CurrentEntry = directory_entry(Iter->path(), Iter->type()); in RealFSDirIter()
412 : directory_entry(Iter->path(), Iter->type()); in increment()
426 //===-----------------------------------------------------------------------===/
428 //===-----------------------------------------------------------------------===/
438 FS->setCurrentWorkingDirectory(getCurrentWorkingDirectory().get()); in pushOverlay()
444 ErrorOr<Status> Status = (*I)->status(Path); in status()
454 if ((*I)->exists(Path)) in exists()
464 auto Result = (*I)->openFileForRead(Path); in openFileForRead()
474 return FSList.front()->getCurrentWorkingDirectory(); in getCurrentWorkingDirectory()
480 if (std::error_code EC = FS->setCurrentWorkingDirectory(Path)) in setCurrentWorkingDirectory()
487 if (FS->exists(Path)) in isLocal()
488 return FS->isLocal(Path, Result); in isLocal()
495 if (FS->exists(Path)) in getRealPath()
496 return FS->getRealPath(Path, Output); in getRealPath()
503 FS->visitChildFileSystems(Callback); in visitChildFileSystems()
517 FS->print(OS, Type, IndentLevel + 1); in printImpl()
551 assert((IsFirstTime || CurrentDirIter != directory_iterator()) && in incrementDirIter()
581 directory_iterator Iter = FS->dir_begin(Dir, FEC); in CombiningDirIterImpl()
668 return N->getKind() == IME_File; in classof()
687 return std::string(Indent, ' ') + "HardLink to -> " + in toString()
692 return N->getKind() == IME_HardLink; in classof()
706 return std::string(Indent, ' ') + "SymbolicLink to -> " + TargetPath; in toString()
716 return N->getKind() == IME_SymbolicLink; in classof()
742 Buf->getBuffer(), Buf->getBufferIdentifier(), RequiresNullTerminator); in getBuffer()
771 return I->second.get(); in getChild()
776 return Entries.emplace(Name, std::move(Child)).first->second.get(); in addChild()
788 Result += Entry.second->toString(Indent + 2); in toString()
793 return N->getKind() == IME_Directory; in classof()
799 // The UniqueID of in-memory files is derived from path and content.
800 // This avoids difficulties in creating exactly equivalent in-memory FSes,
820 : getFileID(DirUID, Name, Buffer ? Buffer->getBuffer() : ""); in makeStatus()
823 Group, Buffer ? Buffer->getBufferSize() : 0, Type, Perms); in makeStatus()
837 return Root->toString(/*Indent=*/0); in toString()
852 assert(!EC); in addFile()
877 detail::InMemoryNode *Node = Dir->getChild(Name); in addFile()
881 StringRef(Path.str().begin(), Name.end() - Path.str().begin()), in addFile()
882 getDirectoryID(Dir->getUniqueID(), Name), in addFile()
885 Dir = cast<detail::InMemoryDirectory>(Dir->addChild( in addFile()
894 detail::InMemoryNode *Node = Dir->getChild(Name); in addFile()
896 Dir->addChild(Name, in addFile()
897 MakeNode({Dir->getUniqueID(), Path, Name, ModificationTime, in addFile()
905 assert((isa<detail::InMemoryFile>(Node) || in addFile()
911 return Link->getResolvedFile().getBuffer()->getBuffer() == in addFile()
912 Buffer->getBuffer(); in addFile()
914 return cast<detail::InMemoryFile>(Node)->getBuffer()->getBuffer() == in addFile()
915 Buffer->getBuffer(); in addFile()
927 -> std::unique_ptr<detail::InMemoryNode> { in addFile()
945 -> std::unique_ptr<detail::InMemoryNode> { in addFileNoOwn()
962 assert(!EC); in lookupNode()
974 detail::InMemoryNode *Node = Dir->getChild(*I); in lookupNode()
988 SmallString<128> TargetPath = Symlink->getTargetPath(); in lookupNode()
1019 return detail::NamedNodeOrError(Path, &File->getResolvedFile()); in lookupNode()
1033 // implementation-defined in POSIX. in addHardLink()
1071 return (*Node)->getStatus(Path); in status()
1081 // When we have a file provide a heap-allocated wrapper for the memory buffer in openFileForRead()
1101 llvm::sys::path::append(Path, I->second->getFileName()); in setCurrentEntry()
1103 switch (I->second->getKind()) { in setCurrentEntry()
1113 FS->lookupNode(Path, /*FollowFinalSymlink=*/true)) { in setCurrentEntry()
1115 Type = (*SymlinkTarget)->getStatus(Path).getType(); in setCurrentEntry()
1167 assert(!EC); in setCurrentWorkingDirectory()
1181 if (!CWD || CWD->empty()) in getRealPath()
1204 //===-----------------------------------------------------------------------===/
1206 //===-----------------------------------------------------------------------===/
1215 if (n != static_cast<size_t>(-1)) in getExistingStyle()
1249 ExternalFS->getCurrentWorkingDirectory()) { in RedirectingFileSystem()
1262 assert((IsFirstTime || Current != End) && "cannot iterate past end"); in incrementImpl()
1267 llvm::sys::path::append(PathStr, (*Current)->getName()); in incrementImpl()
1269 switch ((*Current)->getKind()) { in incrementImpl()
1318 StringRef ExternalPath = ExternalIter->path(); in setCurrentEntry()
1325 CurrentEntry = directory_entry(std::string(NewPath), ExternalIter->type()); in setCurrentEntry()
1367 return ExternalFS->isLocal(Path, Result); in isLocal()
1439 return ExternalFS->dir_begin(Path, EC); in dir_begin()
1449 isFileNotFound(S.getError(), Result->E)) in dir_begin()
1450 return ExternalFS->dir_begin(Dir, EC); in dir_begin()
1456 if (!S->isDirectory()) { in dir_begin()
1465 if (auto ExtRedirect = Result->getExternalRedirect()) { in dir_begin()
1466 auto RE = cast<RedirectingFileSystem::RemapEntry>(Result->E); in dir_begin()
1467 RedirectIter = ExternalFS->dir_begin(*ExtRedirect, RedirectEC); in dir_begin()
1469 if (!RE->useExternalName(UseExternalNames)) { in dir_begin()
1476 auto DE = cast<DirectoryEntry>(Result->E); in dir_begin() local
1479 Path, DE->contents_begin(), DE->contents_end(), RedirectEC)); in dir_begin()
1496 directory_iterator ExternalIter = ExternalFS->dir_begin(Path, ExternalEC); in dir_begin()
1551 R.push_back(Root->getName()); in getRoots()
1568 ExternalFS->print(OS, Type == PrintType::Contents ? PrintType::Summary : Type, in printImpl()
1576 OS << "'" << E->getName() << "'"; in printEntry()
1578 switch (E->getKind()) { in printEntry()
1580 auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(E); in printEntry() local
1584 llvm::make_range(DE->contents_begin(), DE->contents_end())) in printEntry()
1591 OS << " -> '" << RE->getExternalContentsPath() << "'"; in printEntry()
1592 switch (RE->getUseName()) { in printEntry()
1611 ExternalFS->visitChildFileSystems(Callback); in visitChildFileSystems()
1630 Result = S->getValue(Storage); in parseScalarString()
1667 } else if (Value.equals_insensitive("redirect-only")) { in parseRedirectKind()
1681 } else if (Value.equals_insensitive("overlay-dir")) { in parseRootRelativeKind()
1728 for (const auto &Root : FS->Roots) { in lookupOrCreateEntry()
1729 if (Name == Root->getName()) { in lookupOrCreateEntry()
1735 auto *DE = dyn_cast<RedirectingFileSystem::DirectoryEntry>(ParentEntry); in lookupOrCreateEntry() local
1737 llvm::make_range(DE->contents_begin(), DE->contents_end())) { in lookupOrCreateEntry()
1740 if (DirContent && Name == Content->getName()) in lookupOrCreateEntry()
1753 FS->Roots.push_back(std::move(E)); in lookupOrCreateEntry()
1754 ParentEntry = FS->Roots.back().get(); in lookupOrCreateEntry()
1758 auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(ParentEntry); in lookupOrCreateEntry() local
1759 DE->addContent(std::move(E)); in lookupOrCreateEntry()
1760 return DE->getLastContent(); in lookupOrCreateEntry()
1767 StringRef Name = SrcE->getName(); in uniqueOverlayTree()
1768 switch (SrcE->getKind()) { in uniqueOverlayTree()
1770 auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(SrcE); in uniqueOverlayTree() local
1777 llvm::make_range(DE->contents_begin(), DE->contents_end())) in uniqueOverlayTree()
1782 assert(NewParentE && "Parent entry must exist"); in uniqueOverlayTree()
1784 auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(NewParentE); in uniqueOverlayTree() local
1785 DE->addContent( in uniqueOverlayTree()
1787 Name, DR->getExternalContentsPath(), DR->getUseName())); in uniqueOverlayTree()
1791 assert(NewParentE && "Parent entry must exist"); in uniqueOverlayTree()
1793 auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(NewParentE); in uniqueOverlayTree() local
1794 DE->addContent(std::make_unique<RedirectingFileSystem::FileEntry>( in uniqueOverlayTree()
1795 Name, FE->getExternalContentsPath(), FE->getUseName())); in uniqueOverlayTree()
1813 KeyStatusPair("external-contents", false), in parseEntry()
1814 KeyStatusPair("use-external-name", false), in parseEntry()
1855 else if (Value == "directory-remap") in parseEntry()
1864 "entry already has 'contents' or 'external-contents'"); in parseEntry()
1882 } else if (Key == "external-contents") { in parseEntry()
1885 "entry already has 'contents' or 'external-contents'"); in parseEntry()
1893 if (FS->IsRelativeOverlay) { in parseEntry()
1894 FullPath = FS->getOverlayFileDir(); in parseEntry()
1895 assert(!FullPath.empty() && in parseEntry()
1906 } else if (Key == "use-external-name") { in parseEntry()
1922 error(N, "missing key 'contents' or 'external-contents'"); in parseEntry()
1931 error(N, "'use-external-name' is not supported for 'directory' entries"); in parseEntry()
1937 error(N, "'contents' is not supported for 'directory-remap' entries"); in parseEntry()
1955 if (FS->RootRelative == in parseEntry()
1957 StringRef FullPath = FS->getOverlayFileDir(); in parseEntry()
1958 assert(!FullPath.empty() && "Overlay file directory must exist"); in parseEntry()
1959 EC = FS->makeAbsolute(FullPath, Name); in parseEntry()
1965 assert(NameValueNode && "Name presence should be checked earlier"); in parseEntry()
1988 Trimmed = Trimmed.slice(0, Trimmed.size() - 1); in parseEntry()
2042 KeyStatusPair("case-sensitive", false), in parse()
2043 KeyStatusPair("use-external-names", false), in parse()
2044 KeyStatusPair("root-relative", false), in parse()
2045 KeyStatusPair("overlay-relative", false), in parse()
2047 KeyStatusPair("redirecting-with", false), in parse()
2096 } else if (Key == "case-sensitive") { in parse()
2097 if (!parseScalarBool(I.getValue(), FS->CaseSensitive)) in parse()
2099 } else if (Key == "overlay-relative") { in parse()
2100 if (!parseScalarBool(I.getValue(), FS->IsRelativeOverlay)) in parse()
2102 } else if (Key == "use-external-names") { in parse()
2103 if (!parseScalarBool(I.getValue(), FS->UseExternalNames)) in parse()
2106 if (Keys["redirecting-with"].Seen) { in parse()
2108 "'fallthrough' and 'redirecting-with' are mutually exclusive"); in parse()
2117 FS->Redirection = RedirectingFileSystem::RedirectKind::Fallthrough; in parse()
2119 FS->Redirection = RedirectingFileSystem::RedirectKind::RedirectOnly; in parse()
2121 } else if (Key == "redirecting-with") { in parse()
2124 "'fallthrough' and 'redirecting-with' are mutually exclusive"); in parse()
2129 FS->Redirection = *Kind; in parse()
2134 } else if (Key == "root-relative") { in parse()
2136 FS->RootRelative = *Kind; in parse()
2138 error(I.getValue(), "expected valid root-relative kind"); in parse()
2168 yaml::Stream Stream(Buffer->getMemBufferRef(), SM); in create()
2172 yaml::Node *Root = DI->getRoot(); in create()
2184 // Use the YAML path from -ivfsoverlay to compute the dir to be prefixed in create()
2185 // to each 'external-contents' path. in create()
2188 // -ivfsoverlay dummy.cache/vfs/vfs.yaml in create()
2190 // FS->OverlayFileDir => /<absolute_path_to>/dummy.cache/vfs in create()
2194 assert(!EC && "Overlay dir final path must be absolute"); in create()
2196 FS->setOverlayFileDir(OverlayAbsDir); in create()
2210 FS->UseExternalNames = UseExternalNames; in create()
2220 assert(!EC && "Could not make absolute path"); in create()
2238 assert(Parent && "File without a directory?"); in create()
2242 assert(!EC && "Could not make absolute path"); in create()
2251 cast<RedirectingFileSystem::DirectoryEntry>(Parent)->addContent( in create()
2261 assert(E != nullptr); in LookupResult()
2266 SmallString<256> Redirect(DRE->getExternalContentsPath()); in LookupResult()
2268 getExistingStyle(DRE->getExternalContentsPath())); in LookupResult()
2277 llvm::sys::path::append(Result, Parent->getName()); in getPath()
2278 llvm::sys::path::append(Result, E->getName()); in getPath()
2311 if (UsageTrackingActive && Result && isa<RemapEntry>(Result->E)) in lookupPath()
2314 Result->Parents = std::move(Entries); in lookupPath()
2326 assert(!isTraversalComponent(*Start) && in lookupPathImpl()
2327 !isTraversalComponent(From->getName()) && in lookupPathImpl()
2330 StringRef FromName = From->getName(); in lookupPathImpl()
2351 auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(From); in lookupPathImpl() local
2353 llvm::make_range(DE->contents_begin(), DE->contents_end())) { in lookupPathImpl()
2389 ErrorOr<Status> S = ExternalFS->status(RemappedPath); in status()
2395 RE->useExternalName(UseExternalNames), *S); in status()
2398 auto *DE = cast<RedirectingFileSystem::DirectoryEntry>(Result.E); in status() local
2399 return Status::copyWithNewName(DE->getStatus(), LookupPath); in status()
2405 auto Result = ExternalFS->status(LookupPath); in getExternalStatus()
2409 if (!Result || Result->ExposesExternalVFSPath) in getExternalStatus()
2441 isFileNotFound(S.getError(), Result->E)) { in status()
2461 if (ExternalFS->exists(Path)) in exists()
2471 return ExternalFS->exists(Path); in exists()
2475 std::optional<StringRef> ExtRedirect = Result->getExternalRedirect(); in exists()
2477 assert(isa<RedirectingFileSystem::DirectoryEntry>(Result->E)); in exists()
2485 if (ExternalFS->exists(RemappedPath)) in exists()
2492 return ExternalFS->exists(Path); in exists()
2514 return InnerFile->getBuffer(Name, FileSize, RequiresNullTerminator, in getBuffer()
2518 std::error_code close() override { return InnerFile->close(); } in close()
2527 // See \c getRedirectedFileStatus - don't update path if it's exposing an in getWithPath()
2529 if (!Result || (*Result)->status()->ExposesExternalVFSPath) in getWithPath()
2533 auto Name = F->get()->getName(); in getWithPath()
2535 F->get()->setPath(P); in getWithPath()
2550 auto F = File::getWithPath(ExternalFS->openFileForRead(Path), OriginalPath); in openFileForRead()
2561 return File::getWithPath(ExternalFS->openFileForRead(Path), OriginalPath); in openFileForRead()
2565 if (!Result->getExternalRedirect()) // FIXME: errc::not_a_file? in openFileForRead()
2568 StringRef ExtRedirect = *Result->getExternalRedirect(); in openFileForRead()
2573 auto *RE = cast<RedirectingFileSystem::RemapEntry>(Result->E); in openFileForRead()
2576 File::getWithPath(ExternalFS->openFileForRead(RemappedPath), ExtRedirect); in openFileForRead()
2579 isFileNotFound(ExternalFile.getError(), Result->E)) { in openFileForRead()
2583 return File::getWithPath(ExternalFS->openFileForRead(Path), OriginalPath); in openFileForRead()
2588 auto ExternalStatus = (*ExternalFile)->status(); in openFileForRead()
2595 OriginalPath, RE->useExternalName(UseExternalNames), *ExternalStatus); in openFileForRead()
2612 std::error_code EC = ExternalFS->getRealPath(Path, Output); in getRealPath()
2623 return ExternalFS->getRealPath(Path, Output); in getRealPath()
2629 if (auto ExtRedirect = Result->getExternalRedirect()) { in getRealPath()
2630 auto P = ExternalFS->getRealPath(*ExtRedirect, Output); in getRealPath()
2632 isFileNotFound(P, Result->E)) { in getRealPath()
2636 return ExternalFS->getRealPath(Path, Output); in getRealPath()
2644 Result->getPath(Output); in getRealPath()
2663 auto Kind = SrcE->getKind(); in getVFSEntries()
2665 auto *DE = dyn_cast<RedirectingFileSystem::DirectoryEntry>(SrcE); in getVFSEntries() local
2666 assert(DE && "Must be a directory"); in getVFSEntries()
2668 llvm::make_range(DE->contents_begin(), DE->contents_end())) { in getVFSEntries()
2669 Path.push_back(SubEntry->getName()); in getVFSEntries()
2678 assert(DR && "Must be a directory remap"); in getVFSEntries()
2683 YAMLVFSEntry(VPath.c_str(), DR->getExternalContentsPath())); in getVFSEntries()
2687 assert(Kind == RedirectingFileSystem::EK_File && "Must be a EK_File"); in getVFSEntries()
2689 assert(FE && "Must be a file"); in getVFSEntries()
2693 Entries.push_back(YAMLVFSEntry(VPath.c_str(), FE->getExternalContentsPath())); in getVFSEntries()
2708 VFS->lookupPath("/"); in collectVFSFromYAML()
2713 getVFSEntries(RootResult->E, Components, CollectedEntries); in collectVFSFromYAML()
2726 assert(sys::path::is_absolute(VirtualPath) && "virtual path not absolute"); in addEntry()
2727 assert(sys::path::is_absolute(RealPath) && "real path not absolute"); in addEntry()
2728 assert(!pathHasTraversal(VirtualPath) && "path traversal is not supported"); in addEntry()
2781 assert(!Parent.empty()); in containedPart()
2782 assert(containedIn(Parent, Path)); in containedPart()
2810 OS.indent(Indent + 2) << "'external-contents': \"" in writeEntry()
2825 OS << " 'case-sensitive': '" << (*IsCaseSensitive ? "true" : "false") in write()
2828 OS << " 'use-external-names': '" << (*UseExternalNames ? "true" : "false") in write()
2833 OS << " 'overlay-relative': '" << (UseOverlayRelative ? "true" : "false") in write()
2847 assert(RPath.starts_with(OverlayDir) && in write()
2880 assert(RPath.starts_with(OverlayDir) && in write()
2913 directory_iterator I = FS->dir_begin(Path, EC); in recursive_directory_iterator()
2916 State->Stack.push_back(I); in recursive_directory_iterator()
2922 assert(FS && State && !State->Stack.empty() && "incrementing past end"); in increment()
2923 assert(!State->Stack.back()->path().empty() && "non-canonical end iterator"); in increment()
2926 if (State->HasNoPushRequest) in increment()
2927 State->HasNoPushRequest = false; in increment()
2929 if (State->Stack.back()->type() == sys::fs::file_type::directory_file) { in increment()
2931 FS->dir_begin(State->Stack.back()->path(), EC); in increment()
2933 State->Stack.push_back(I); in increment()
2939 while (!State->Stack.empty() && State->Stack.back().increment(EC) == End) in increment()
2940 State->Stack.pop_back(); in increment()
2942 if (State->Stack.empty()) in increment()