diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h index b475d3d1be329b..590e5e95a35f17 100644 --- a/llvm/include/llvm/Support/VirtualFileSystem.h +++ b/llvm/include/llvm/Support/VirtualFileSystem.h @@ -513,18 +513,20 @@ class InMemoryFileSystem : public FileSystem { Optional Perms = None); /// Add a hard link to a file. + /// /// Here hard links are not intended to be fully equivalent to the classical /// filesystem. Both the hard link and the file share the same buffer and /// status (and thus have the same UniqueID). Because of this there is no way /// to distinguish between the link and the file after the link has been /// added. /// - /// The To path must be an existing file or a hardlink. The From file must not - /// have been added before. The To Path must not be a directory. The From Node - /// is added as a hard link which points to the resolved file of To Node. + /// The \param Target path must be an existing file or a hardlink. The + /// \param NewLink file must not have been added before. The \param Target + /// path must not be a directory. The \param NewLink node is added as a hard + /// link which points to the resolved file of \param Target node. /// \return true if the above condition is satisfied and hardlink was /// successfully created, false otherwise. - bool addHardLink(const Twine &From, const Twine &To); + bool addHardLink(const Twine &NewLink, const Twine &Target); /// Add a buffer to the VFS with a path. The VFS does not own the buffer. /// If present, User, Group, Type and Perms apply to the newly-created file diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index d94554bc1be9ae..526792281aa735 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -941,18 +941,19 @@ lookupInMemoryNode(const InMemoryFileSystem &FS, detail::InMemoryDirectory *Dir, } } -bool InMemoryFileSystem::addHardLink(const Twine &FromPath, - const Twine &ToPath) { - auto FromNode = lookupInMemoryNode(*this, Root.get(), FromPath); - auto ToNode = lookupInMemoryNode(*this, Root.get(), ToPath); +bool InMemoryFileSystem::addHardLink(const Twine &NewLink, + const Twine &Target) { + auto NewLinkNode = lookupInMemoryNode(*this, Root.get(), NewLink); + auto TargetNode = lookupInMemoryNode(*this, Root.get(), Target); // FromPath must not have been added before. ToPath must have been added // before. Resolved ToPath must be a File. - if (!ToNode || FromNode || !isa(*ToNode)) + if (!TargetNode || NewLinkNode || !isa(*TargetNode)) return false; - return addFile(FromPath, 0, nullptr, None, None, None, None, + return addFile(NewLink, 0, nullptr, None, None, None, None, [&](detail::NewInMemoryNodeInfo NNI) { return std::make_unique( - NNI.Path.str(), *cast(*ToNode)); + NNI.Path.str(), + *cast(*TargetNode)); }); }