mirror of
https://github.com/NixOS/nix
synced 2025-07-06 00:51:47 +02:00
Merge pull request #11959 from Mic92/better-errors
more readable errors if symlinks cannot be created
This commit is contained in:
commit
d0f84fd2a5
3 changed files with 14 additions and 6 deletions
|
@ -602,7 +602,11 @@ std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix)
|
|||
|
||||
void createSymlink(const Path & target, const Path & link)
|
||||
{
|
||||
fs::create_symlink(target, link);
|
||||
try {
|
||||
fs::create_symlink(target, link);
|
||||
} catch (fs::filesystem_error & e) {
|
||||
throw SysError("creating symlink '%1%' -> '%2%'", link, target);
|
||||
}
|
||||
}
|
||||
|
||||
void replaceSymlink(const fs::path & target, const fs::path & link)
|
||||
|
@ -615,10 +619,16 @@ void replaceSymlink(const fs::path & target, const fs::path & link)
|
|||
fs::create_symlink(target, tmp);
|
||||
} catch (fs::filesystem_error & e) {
|
||||
if (e.code() == std::errc::file_exists) continue;
|
||||
throw;
|
||||
throw SysError("creating symlink '%1%' -> '%2%'", tmp, target);
|
||||
}
|
||||
|
||||
try {
|
||||
fs::rename(tmp, link);
|
||||
} catch (fs::filesystem_error & e) {
|
||||
if (e.code() == std::errc::file_exists) continue;
|
||||
throw SysError("renaming '%1%' to '%2%'", tmp, link);
|
||||
}
|
||||
|
||||
fs::rename(tmp, link);
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -250,8 +250,6 @@ void setWriteTime(const std::filesystem::path & path, const struct stat & st);
|
|||
/**
|
||||
* Create a symlink.
|
||||
*
|
||||
* In the process of being deprecated for
|
||||
* `std::filesystem::create_symlink`.
|
||||
*/
|
||||
void createSymlink(const Path & target, const Path & link);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue