mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
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.
This commit is contained in:
parent
143fb88ceb
commit
5b59be914d
6 changed files with 9 additions and 38 deletions
|
@ -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"
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<struct stat> 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)
|
||||
|
|
|
@ -126,26 +126,8 @@ std::optional<struct stat> 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.
|
||||
|
|
|
@ -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<void(Value & v, const PosIdx pos, const fs::path & path)> recurse;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue