mirror of
https://github.com/NixOS/nix.git
synced 2025-12-03 23:51:00 +01:00
Merge pull request #14679 from NixOS/backport-14676-to-2.31-maintenance
[Backport 2.31-maintenance] libstore: Use makeTempPath in optimizePath_, assorted fs fixes
This commit is contained in:
commit
315010c447
3 changed files with 15 additions and 8 deletions
|
|
@ -234,7 +234,7 @@ void LocalStore::optimisePath_(
|
||||||
its timestamp back to 0. */
|
its timestamp back to 0. */
|
||||||
MakeReadOnly makeReadOnly(mustToggle ? dirOfPath : "");
|
MakeReadOnly makeReadOnly(mustToggle ? dirOfPath : "");
|
||||||
|
|
||||||
std::filesystem::path tempLink = fmt("%1%/.tmp-link-%2%-%3%", config->realStoreDir, getpid(), rand());
|
std::filesystem::path tempLink = makeTempPath(config->realStoreDir.get(), ".tmp-link");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::filesystem::create_hard_link(linkPath, tempLink);
|
std::filesystem::create_hard_link(linkPath, tempLink);
|
||||||
|
|
@ -255,8 +255,12 @@ void LocalStore::optimisePath_(
|
||||||
try {
|
try {
|
||||||
std::filesystem::rename(tempLink, path);
|
std::filesystem::rename(tempLink, path);
|
||||||
} catch (std::filesystem::filesystem_error & e) {
|
} catch (std::filesystem::filesystem_error & e) {
|
||||||
std::filesystem::remove(tempLink);
|
{
|
||||||
printError("unable to unlink %1%", tempLink);
|
std::error_code ec;
|
||||||
|
remove(tempLink, ec); /* Clean up after ourselves. */
|
||||||
|
if (ec)
|
||||||
|
printError("unable to unlink %1%: %2%", tempLink, ec.message());
|
||||||
|
}
|
||||||
if (e.code() == std::errc::too_many_links) {
|
if (e.code() == std::errc::too_many_links) {
|
||||||
/* Some filesystems generate too many links on the rename,
|
/* Some filesystems generate too many links on the rename,
|
||||||
rather than on the original link. (Probably it
|
rather than on the original link. (Probably it
|
||||||
|
|
|
||||||
|
|
@ -730,11 +730,10 @@ Path makeTempPath(const Path & root, const Path & suffix)
|
||||||
|
|
||||||
void createSymlink(const Path & target, const Path & link)
|
void createSymlink(const Path & target, const Path & link)
|
||||||
{
|
{
|
||||||
try {
|
std::error_code ec;
|
||||||
std::filesystem::create_symlink(target, link);
|
std::filesystem::create_symlink(target, link, ec);
|
||||||
} catch (std::filesystem::filesystem_error & e) {
|
if (ec)
|
||||||
throw SysError("creating symlink '%1%' -> '%2%'", link, target);
|
throw SysError(ec.value(), "creating symlink '%1%' -> '%2%'", link, target);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void replaceSymlink(const std::filesystem::path & target, const std::filesystem::path & link)
|
void replaceSymlink(const std::filesystem::path & target, const std::filesystem::path & link)
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,10 @@ class AutoDelete
|
||||||
public:
|
public:
|
||||||
AutoDelete();
|
AutoDelete();
|
||||||
AutoDelete(const std::filesystem::path & p, bool recursive = true);
|
AutoDelete(const std::filesystem::path & p, bool recursive = true);
|
||||||
|
AutoDelete(AutoDelete &&) = delete;
|
||||||
|
AutoDelete(const AutoDelete &) = delete;
|
||||||
|
AutoDelete & operator=(AutoDelete &&) = delete;
|
||||||
|
AutoDelete & operator=(const AutoDelete &) = delete;
|
||||||
~AutoDelete();
|
~AutoDelete();
|
||||||
|
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue