Merge pull request #10665 from siddhantk232/stdfs

Remove `isLink` in favor of `std::filesystem::is_link`

This is one step closer to eventually getting rid of most of our file system utils (in `file-system.cc`) in favor of the `std::filesystem`.
This commit is contained in:
John Ericson 2024-05-08 10:55:19 -04:00 committed by GitHub
commit 0930058189
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 6 additions and 13 deletions

View file

@ -33,8 +33,9 @@ Path IndirectRootStore::addPermRoot(const StorePath & storePath, const Path & _g
/* Don't clobber the link if it already exists and doesn't
point to the Nix store. */
if (pathExists(gcRoot) && (!isLink(gcRoot) || !isInStore(readLink(gcRoot))))
if (pathExists(gcRoot) && (!std::filesystem::is_symlink(gcRoot) || !isInStore(readLink(gcRoot))))
throw Error("cannot create symlink '%1%'; already exists", gcRoot);
makeSymlink(gcRoot, printStorePath(storePath));
addIndirectRoot(gcRoot);

View file

@ -54,7 +54,7 @@ Path Store::followLinksToStore(std::string_view _path) const
{
Path path = absPath(std::string(_path));
while (!isInStore(path)) {
if (!isLink(path)) break;
if (!std::filesystem::is_symlink(path)) break;
auto target = readLink(path);
path = absPath(target, dirOf(path));
}

View file

@ -94,7 +94,7 @@ Path canonPath(PathView path, bool resolveSymlinks)
path,
[&followCount, &temp, maxFollow, resolveSymlinks]
(std::string & result, std::string_view & remaining) {
if (resolveSymlinks && isLink(result)) {
if (resolveSymlinks && std::filesystem::is_symlink(result)) {
if (++followCount >= maxFollow)
throw Error("infinite symlink recursion in path '%0%'", remaining);
remaining = (temp = concatStrings(readLink(result), remaining));
@ -222,12 +222,6 @@ Path readLink(const Path & path)
}
bool isLink(const Path & path)
{
return getFileType(path) == fs::file_type::symlink;
}
std::vector<fs::directory_entry> readDirectory(const Path & path)
{
std::vector<fs::directory_entry> entries;

View file

@ -117,8 +117,6 @@ bool pathAccessible(const Path & path);
*/
Path readLink(const Path & path);
bool isLink(const Path & path);
/**
* Read the contents of a directory. The entries `.` and `..` are
* removed.

View file

@ -101,7 +101,7 @@ struct CmdConfigCheck : StoreCommand
Path userEnv = canonPath(profileDir, true);
if (store->isStorePath(userEnv) && hasSuffix(userEnv, "user-environment")) {
while (profileDir.find("/profiles/") == std::string::npos && isLink(profileDir))
while (profileDir.find("/profiles/") == std::string::npos && std::filesystem::is_symlink(profileDir))
profileDir = absPath(readLink(profileDir), dirOf(profileDir));
if (profileDir.find("/profiles/") == std::string::npos)

View file

@ -121,7 +121,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
Path profileDir = dirOf(where);
// Resolve profile to /nix/var/nix/profiles/<name> link.
while (canonPath(profileDir).find("/profiles/") == std::string::npos && isLink(profileDir))
while (canonPath(profileDir).find("/profiles/") == std::string::npos && std::filesystem::is_symlink(profileDir))
profileDir = readLink(profileDir);
printInfo("found profile '%s'", profileDir);