mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-29 17:16:15 +02:00
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:
commit
0930058189
6 changed files with 6 additions and 13 deletions
|
@ -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
|
/* Don't clobber the link if it already exists and doesn't
|
||||||
point to the Nix store. */
|
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);
|
throw Error("cannot create symlink '%1%'; already exists", gcRoot);
|
||||||
|
|
||||||
makeSymlink(gcRoot, printStorePath(storePath));
|
makeSymlink(gcRoot, printStorePath(storePath));
|
||||||
addIndirectRoot(gcRoot);
|
addIndirectRoot(gcRoot);
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ Path Store::followLinksToStore(std::string_view _path) const
|
||||||
{
|
{
|
||||||
Path path = absPath(std::string(_path));
|
Path path = absPath(std::string(_path));
|
||||||
while (!isInStore(path)) {
|
while (!isInStore(path)) {
|
||||||
if (!isLink(path)) break;
|
if (!std::filesystem::is_symlink(path)) break;
|
||||||
auto target = readLink(path);
|
auto target = readLink(path);
|
||||||
path = absPath(target, dirOf(path));
|
path = absPath(target, dirOf(path));
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ Path canonPath(PathView path, bool resolveSymlinks)
|
||||||
path,
|
path,
|
||||||
[&followCount, &temp, maxFollow, resolveSymlinks]
|
[&followCount, &temp, maxFollow, resolveSymlinks]
|
||||||
(std::string & result, std::string_view & remaining) {
|
(std::string & result, std::string_view & remaining) {
|
||||||
if (resolveSymlinks && isLink(result)) {
|
if (resolveSymlinks && std::filesystem::is_symlink(result)) {
|
||||||
if (++followCount >= maxFollow)
|
if (++followCount >= maxFollow)
|
||||||
throw Error("infinite symlink recursion in path '%0%'", remaining);
|
throw Error("infinite symlink recursion in path '%0%'", remaining);
|
||||||
remaining = (temp = concatStrings(readLink(result), 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> readDirectory(const Path & path)
|
||||||
{
|
{
|
||||||
std::vector<fs::directory_entry> entries;
|
std::vector<fs::directory_entry> entries;
|
||||||
|
|
|
@ -117,8 +117,6 @@ bool pathAccessible(const Path & path);
|
||||||
*/
|
*/
|
||||||
Path readLink(const Path & path);
|
Path readLink(const Path & path);
|
||||||
|
|
||||||
bool isLink(const Path & path);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the contents of a directory. The entries `.` and `..` are
|
* Read the contents of a directory. The entries `.` and `..` are
|
||||||
* removed.
|
* removed.
|
||||||
|
|
|
@ -101,7 +101,7 @@ struct CmdConfigCheck : StoreCommand
|
||||||
Path userEnv = canonPath(profileDir, true);
|
Path userEnv = canonPath(profileDir, true);
|
||||||
|
|
||||||
if (store->isStorePath(userEnv) && hasSuffix(userEnv, "user-environment")) {
|
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));
|
profileDir = absPath(readLink(profileDir), dirOf(profileDir));
|
||||||
|
|
||||||
if (profileDir.find("/profiles/") == std::string::npos)
|
if (profileDir.find("/profiles/") == std::string::npos)
|
||||||
|
|
|
@ -121,7 +121,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
|
||||||
Path profileDir = dirOf(where);
|
Path profileDir = dirOf(where);
|
||||||
|
|
||||||
// Resolve profile to /nix/var/nix/profiles/<name> link.
|
// 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);
|
profileDir = readLink(profileDir);
|
||||||
|
|
||||||
printInfo("found profile '%s'", profileDir);
|
printInfo("found profile '%s'", profileDir);
|
||||||
|
|
Loading…
Reference in a new issue