Skip to content

Commit 5b59be9

Browse files
committed
Replace symlink_exists with pathExists
As it turns out the orignal implementation of symlink_exists cannot be used in Nix because it did now std::filesystem::filesystem_error. The new implementation fixes that but is now actually the same as pathExists except for the path type.
1 parent 143fb88 commit 5b59be9

File tree

6 files changed

+9
-38
lines changed

6 files changed

+9
-38
lines changed

src/libfetchers/git.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ struct GitInputScheme : InputScheme
533533
static MakeNotAllowedError makeNotAllowedError(std::filesystem::path repoPath)
534534
{
535535
return [repoPath{std::move(repoPath)}](const CanonPath & path) -> RestrictedPathError {
536-
if (fs::symlink_exists(repoPath / path.rel()))
536+
if (pathExists(repoPath / path.rel()))
537537
return RestrictedPathError(
538538
"Path '%1%' in the repository %2% is not tracked by Git.\n"
539539
"\n"

src/libflake/flake.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ LockedFlake lockFlake(
811811
auto relPath = (topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock";
812812
auto outputLockFilePath = *sourcePath / relPath;
813813

814-
bool lockFileExists = fs::symlink_exists(outputLockFilePath);
814+
bool lockFileExists = pathExists(outputLockFilePath);
815815

816816
auto s = chomp(diff);
817817
if (lockFileExists) {

src/libstore/unix/build/derivation-builder.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,9 +1969,10 @@ void DerivationBuilderImpl::runChild()
19691969
if (pathExists(path))
19701970
ss.push_back(path);
19711971

1972-
if (settings.caFile != "" && pathExists(settings.caFile)) {
1972+
if (settings.caFile != "") {
19731973
Path caFile = settings.caFile;
1974-
pathsInChroot.try_emplace("/etc/ssl/certs/ca-certificates.crt", canonPath(caFile, true), true);
1974+
if (pathExists(caFile))
1975+
pathsInChroot.try_emplace("/etc/ssl/certs/ca-certificates.crt", canonPath(caFile, true), true);
19751976
}
19761977
}
19771978

src/libutil/file-system.cc

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,6 @@
3131

3232
namespace nix {
3333

34-
namespace fs {
35-
using namespace std::filesystem;
36-
37-
bool symlink_exists(const std::filesystem::path & path) {
38-
try {
39-
return std::filesystem::exists(std::filesystem::symlink_status(path));
40-
} catch (const std::filesystem::filesystem_error & e) {
41-
throw SysError("cannot check existence of %1%", path);
42-
}
43-
}
44-
}
45-
4634
DirectoryIterator::DirectoryIterator(const std::filesystem::path& p) {
4735
try {
4836
// **Attempt to create the underlying directory_iterator**
@@ -243,9 +231,9 @@ std::optional<struct stat> maybeLstat(const Path & path)
243231
}
244232

245233

246-
bool pathExists(const Path & path)
234+
bool pathExists(const std::filesystem::path & path)
247235
{
248-
return maybeLstat(path).has_value();
236+
return maybeLstat(path.string()).has_value();
249237
}
250238

251239
bool pathAccessible(const std::filesystem::path & path)

src/libutil/include/nix/util/file-system.hh

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,8 @@ std::optional<struct stat> maybeLstat(const Path & path);
126126

127127
/**
128128
* @return true iff the given path exists.
129-
*
130-
* In the process of being deprecated for `fs::symlink_exists`.
131-
*/
132-
bool pathExists(const Path & path);
133-
134-
namespace fs {
135-
136-
/**
137-
* TODO: we may actually want to use pathExists instead of this function
138-
* ```
139-
* symlink_exists(p) = std::filesystem::exists(std::filesystem::symlink_status(p))
140-
* ```
141-
* Missing convenience analogous to
142-
* ```
143-
* std::filesystem::exists(p) = std::filesystem::exists(std::filesystem::status(p))
144-
* ```
145129
*/
146-
bool symlink_exists(const std::filesystem::path & path);
147-
148-
} // namespace fs
130+
bool pathExists(const std::filesystem::path & path);
149131

150132
/**
151133
* Canonicalize a path except for the last component.

src/nix/eval.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption
7676
if (writeTo) {
7777
logger->stop();
7878

79-
if (fs::symlink_exists(*writeTo))
79+
if (pathExists(*writeTo))
8080
throw Error("path '%s' already exists", writeTo->string());
8181

8282
std::function<void(Value & v, const PosIdx pos, const fs::path & path)> recurse;

0 commit comments

Comments
 (0)