diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 80c5884f7..492867dc4 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -533,7 +533,7 @@ struct GitInputScheme : InputScheme static MakeNotAllowedError makeNotAllowedError(std::filesystem::path repoPath) { return [repoPath{std::move(repoPath)}](const CanonPath & path) -> RestrictedPathError { - if (fs::symlink_exists(repoPath / path.rel())) + if (pathExists(repoPath / path.rel())) return RestrictedPathError( "Path '%1%' in the repository %2% is not tracked by Git.\n" "\n" diff --git a/src/libflake/flake.cc b/src/libflake/flake.cc index 28e3c4b93..a086251b9 100644 --- a/src/libflake/flake.cc +++ b/src/libflake/flake.cc @@ -811,7 +811,7 @@ LockedFlake lockFlake( auto relPath = (topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock"; auto outputLockFilePath = *sourcePath / relPath; - bool lockFileExists = fs::symlink_exists(outputLockFilePath); + bool lockFileExists = pathExists(outputLockFilePath); auto s = chomp(diff); if (lockFileExists) { diff --git a/src/libstore/unix/build/derivation-builder.cc b/src/libstore/unix/build/derivation-builder.cc index 76f69671c..4bde9750d 100644 --- a/src/libstore/unix/build/derivation-builder.cc +++ b/src/libstore/unix/build/derivation-builder.cc @@ -1969,9 +1969,10 @@ void DerivationBuilderImpl::runChild() if (pathExists(path)) ss.push_back(path); - if (settings.caFile != "" && pathExists(settings.caFile)) { + if (settings.caFile != "") { Path caFile = settings.caFile; - pathsInChroot.try_emplace("/etc/ssl/certs/ca-certificates.crt", canonPath(caFile, true), true); + if (pathExists(caFile)) + pathsInChroot.try_emplace("/etc/ssl/certs/ca-certificates.crt", canonPath(caFile, true), true); } } diff --git a/src/libutil/file-system.cc b/src/libutil/file-system.cc index f6e399774..edd68d6e5 100644 --- a/src/libutil/file-system.cc +++ b/src/libutil/file-system.cc @@ -31,18 +31,6 @@ namespace nix { -namespace fs { - using namespace std::filesystem; - - bool symlink_exists(const std::filesystem::path & path) { - try { - return std::filesystem::exists(std::filesystem::symlink_status(path)); - } catch (const std::filesystem::filesystem_error & e) { - throw SysError("cannot check existence of %1%", path); - } - } -} - DirectoryIterator::DirectoryIterator(const std::filesystem::path& p) { try { // **Attempt to create the underlying directory_iterator** @@ -243,9 +231,9 @@ std::optional maybeLstat(const Path & path) } -bool pathExists(const Path & path) +bool pathExists(const std::filesystem::path & path) { - return maybeLstat(path).has_value(); + return maybeLstat(path.string()).has_value(); } bool pathAccessible(const std::filesystem::path & path) diff --git a/src/libutil/include/nix/util/file-system.hh b/src/libutil/include/nix/util/file-system.hh index 9afab46ab..1d7b5e3aa 100644 --- a/src/libutil/include/nix/util/file-system.hh +++ b/src/libutil/include/nix/util/file-system.hh @@ -126,26 +126,8 @@ std::optional maybeLstat(const Path & path); /** * @return true iff the given path exists. - * - * In the process of being deprecated for `fs::symlink_exists`. */ -bool pathExists(const Path & path); - -namespace fs { - -/** - * TODO: we may actually want to use pathExists instead of this function - * ``` - * symlink_exists(p) = std::filesystem::exists(std::filesystem::symlink_status(p)) - * ``` - * Missing convenience analogous to - * ``` - * std::filesystem::exists(p) = std::filesystem::exists(std::filesystem::status(p)) - * ``` - */ -bool symlink_exists(const std::filesystem::path & path); - -} // namespace fs +bool pathExists(const std::filesystem::path & path); /** * Canonicalize a path except for the last component. diff --git a/src/nix/eval.cc b/src/nix/eval.cc index 6a9bd2f16..858531642 100644 --- a/src/nix/eval.cc +++ b/src/nix/eval.cc @@ -76,7 +76,7 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption if (writeTo) { logger->stop(); - if (fs::symlink_exists(*writeTo)) + if (pathExists(*writeTo)) throw Error("path '%s' already exists", writeTo->string()); std::function recurse;