1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-11 11:31:03 +01:00

Merge pull request #14676 from NixOS/fs-fixes

libstore: Use makeTempPath in optimizePath_, assorted fs fixes
This commit is contained in:
John Ericson 2025-12-01 01:55:20 +00:00 committed by GitHub
commit 1e9b1ff851
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 8 deletions

View file

@ -234,7 +234,7 @@ void LocalStore::optimisePath_(
its timestamp back to 0. */
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 {
std::filesystem::create_hard_link(linkPath, tempLink);
@ -255,8 +255,12 @@ void LocalStore::optimisePath_(
try {
std::filesystem::rename(tempLink, path);
} 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) {
/* Some filesystems generate too many links on the rename,
rather than on the original link. (Probably it