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

libstore: Actually correctly call remove in case rename fails

This commit is contained in:
Sergei Zimmerman 2025-12-01 02:56:44 +03:00
parent d888846b68
commit 1cc337bb5f
No known key found for this signature in database

View file

@ -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