about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-08-29T12·49+0200
committerEelco Dolstra <edolstra@gmail.com>2019-08-29T12·49+0200
commita2c4fcd5e9782dc8d2998773380c7171ee53b813 (patch)
tree8ded004bb7d06f44dd28c08c922771238cc85cea
parent31f5ecfaa5bce2282f50daed1e4f477c64705fb3 (diff)
Don't rely on st_blocks
It doesn't seem very reliable on ZFS.
-rw-r--r--src/libstore/gc.cc7
-rw-r--r--src/libutil/util.cc2
-rw-r--r--tests/gc-auto.sh4
3 files changed, 6 insertions, 7 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index f736016797a2..a166f4ee2483 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -690,9 +690,8 @@ void LocalStore::removeUnusedLinks(const GCState & state)
             throw SysError(format("statting '%1%'") % path);
 
         if (st.st_nlink != 1) {
-            unsigned long long size = st.st_blocks * 512ULL;
-            actualSize += size;
-            unsharedSize += (st.st_nlink - 1) * size;
+            actualSize += st.st_size;
+            unsharedSize += (st.st_nlink - 1) * st.st_size;
             continue;
         }
 
@@ -701,7 +700,7 @@ void LocalStore::removeUnusedLinks(const GCState & state)
         if (unlink(path.c_str()) == -1)
             throw SysError(format("deleting '%1%'") % path);
 
-        state.results.bytesFreed += st.st_blocks * 512ULL;
+        state.results.bytesFreed += st.st_size;
     }
 
     struct stat st;
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 44fa72482552..1b744999153a 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -397,7 +397,7 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed)
     }
 
     if (!S_ISDIR(st.st_mode) && st.st_nlink == 1)
-        bytesFreed += st.st_blocks * 512;
+        bytesFreed += st.st_size;
 
     if (S_ISDIR(st.st_mode)) {
         /* Make the directory accessible. */
diff --git a/tests/gc-auto.sh b/tests/gc-auto.sh
index 68b7219f238d..54ead227ef62 100644
--- a/tests/gc-auto.sh
+++ b/tests/gc-auto.sh
@@ -22,7 +22,7 @@ with import ./config.nix; mkDerivation {
     echo foo > \$out/bar
     echo 1...
     sleep 2
-    echo 100 > $fake_free
+    echo 200 > $fake_free
     echo 2...
     sleep 2
     echo 3...
@@ -44,7 +44,7 @@ with import ./config.nix; mkDerivation {
     echo foo > \$out/bar
     echo 1...
     sleep 2
-    echo 100 > $fake_free
+    echo 200 > $fake_free
     echo 2...
     sleep 2
     echo 3...