diff --git a/src/libstore/indirect-root-store.cc b/src/libstore/indirect-root-store.cc index 9da05778d..082a458ab 100644 --- a/src/libstore/indirect-root-store.cc +++ b/src/libstore/indirect-root-store.cc @@ -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); diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 008cc11e7..cefb5befd 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -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)); } diff --git a/src/libutil/file-system.cc b/src/libutil/file-system.cc index 03f64edc7..47251dbd7 100644 --- a/src/libutil/file-system.cc +++ b/src/libutil/file-system.cc @@ -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 readDirectory(const Path & path) { std::vector entries; diff --git a/src/libutil/file-system.hh b/src/libutil/file-system.hh index 40ed82f02..5a0688104 100644 --- a/src/libutil/file-system.hh +++ b/src/libutil/file-system.hh @@ -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. diff --git a/src/nix/config-check.cc b/src/nix/config-check.cc index f23e36fb5..9575bf338 100644 --- a/src/nix/config-check.cc +++ b/src/nix/config-check.cc @@ -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) diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index a64b6a56e..17d1edb97 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -121,7 +121,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand Path profileDir = dirOf(where); // Resolve profile to /nix/var/nix/profiles/ 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);