mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
symlink_exists: wrap exceptions into nix exception
(cherry picked from commit 779687854f
)
This commit is contained in:
parent
c972cbd2bb
commit
d73ed6f310
2 changed files with 13 additions and 4 deletions
|
@ -31,7 +31,17 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
namespace fs { using namespace std::filesystem; }
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool isAbsolute(PathView path)
|
bool isAbsolute(PathView path)
|
||||||
{
|
{
|
||||||
|
|
|
@ -134,6 +134,7 @@ bool pathExists(const Path & path);
|
||||||
namespace fs {
|
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))
|
* symlink_exists(p) = std::filesystem::exists(std::filesystem::symlink_status(p))
|
||||||
* ```
|
* ```
|
||||||
|
@ -142,9 +143,7 @@ namespace fs {
|
||||||
* std::filesystem::exists(p) = std::filesystem::exists(std::filesystem::status(p))
|
* std::filesystem::exists(p) = std::filesystem::exists(std::filesystem::status(p))
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
inline bool symlink_exists(const std::filesystem::path & path) {
|
bool symlink_exists(const std::filesystem::path & path);
|
||||||
return std::filesystem::exists(std::filesystem::symlink_status(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace fs
|
} // namespace fs
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue