diff mbox series

[bug#50327,1/2] daemon: Print which disk(s) are how full.

Message ID 20210901192545.12347-1-me@tobias.gr
State New
Headers show
Series Improved ‘free disk space’ message + a question | expand

Commit Message

Tobias Geerinckx-Rice Sept. 1, 2021, 7:25 p.m. UTC
* nix/libstore/build.cc (pathFull): New function.
(DerivationGoal::buildDone): Use it.
---
 nix/libstore/build.cc | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

Comments

Ludovic Courtès Sept. 18, 2021, 9:53 a.m. UTC | #1
Tobias Geerinckx-Rice <me@tobias.gr> skribis:

> * nix/libstore/build.cc (pathFull): New function.
> (DerivationGoal::buildDone): Use it.

I’d call it ‘directoryFull’ or ‘partitionFull’.  Otherwise LGTM!

Ludo’.
diff mbox series

Patch

diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 5697ae5a43..963cddb98b 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -1297,6 +1297,25 @@  void replaceValidPath(const Path & storePath, const Path tmpPath)
         deletePath(oldPath);
 }
 
+static bool pathFull(Path path)
+{
+#if HAVE_STATVFS
+    unsigned long long required = 8ULL * 1024 * 1024; // FIXME: make configurable
+    struct statvfs st;
+
+    if (statvfs(path.c_str(), &st) == 0) {
+        unsigned long long free = (unsigned long long) st.f_bavail * st.f_bsize;
+        if (free < required) {
+            printMsg(lvlError, format("note: only %1$.2f MiB available in ‘%2%’")
+                                      % (free / (1024.0 * 1024.0)) % path);
+            return true;
+        }
+    }
+#endif
+
+    return false;
+}
+
 
 MakeError(NotDeterministic, BuildError)
 
@@ -1355,16 +1374,10 @@  void DerivationGoal::buildDone()
                of knowing whether the build actually got an ENOSPC.
                So instead, check if the disk is (nearly) full now.  If
                so, we don't mark this build as a permanent failure. */
-#if HAVE_STATVFS
-            unsigned long long required = 8ULL * 1024 * 1024; // FIXME: make configurable
-            struct statvfs st;
-            if (statvfs(settings.nixStore.c_str(), &st) == 0 &&
-                (unsigned long long) st.f_bavail * st.f_bsize < required)
+            if (pathFull(settings.nixStore))
                 diskFull = true;
-            if (statvfs(tmpDir.c_str(), &st) == 0 &&
-                (unsigned long long) st.f_bavail * st.f_bsize < required)
+            if (pathFull(tmpDir))
                 diskFull = true;
-#endif
 
             deleteTmpDir(false);