summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-06-25 10:07:09 +0200
committerLudovic Courtès <ludo@gnu.org>2020-06-25 12:29:22 +0200
commitb930f0ba2115f71c323d4bf3d72efb763f716296 (patch)
tree66fdfe72abdde53aff37050ac35a1fb7594b684c /nix
parentb06ba9e0ff79d3130a81ee48a11a27af6330dcf0 (diff)
downloadguix-b930f0ba2115f71c323d4bf3d72efb763f716296.tar.gz
daemon: Correctly handle EMLINK corner case when deduplicating.
Suggested by Caleb Ristvedt <caleb.ristvedt@cune.org>.

* nix/libstore/optimise-store.cc (LocalStore::optimisePath_): Save errno
from 'rename' before calling 'unlink'.
Diffstat (limited to 'nix')
-rw-r--r--nix/libstore/optimise-store.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/nix/libstore/optimise-store.cc b/nix/libstore/optimise-store.cc
index d8f8d2394b..eb303ab4c3 100644
--- a/nix/libstore/optimise-store.cc
+++ b/nix/libstore/optimise-store.cc
@@ -215,9 +215,10 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path, InodeHa
 
     /* Atomically replace the old file with the new hard link. */
     if (rename(tempLink.c_str(), path.c_str()) == -1) {
+	int renameErrno = errno;
         if (unlink(tempLink.c_str()) == -1)
             printMsg(lvlError, format("unable to unlink `%1%'") % tempLink);
-        if (errno == EMLINK) {
+        if (renameErrno == EMLINK) {
             /* Some filesystems generate too many links on the rename,
                rather than on the original link.  (Probably it
                temporarily increases the st_nlink field before