summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-06-22 15:54:55 +0200
committerLudovic Courtès <ludo@gnu.org>2015-07-02 22:52:59 +0200
commit5e0a9ae2e25a1016389f4893a6ed6682aadcf51d (patch)
treea1501e360dc885641fdd7f06f09af31d73d9bd62
parent4e5ab98d6d14f8b0e3bd1d77b2f4f2354e7a49a8 (diff)
downloadguix-5e0a9ae2e25a1016389f4893a6ed6682aadcf51d.tar.gz
Use posix_fallocate to create /nix/var/nix/db/reserved
-rw-r--r--nix/libstore/local-store.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc
index 9d8ae718f6..b2c78477b6 100644
--- a/nix/libstore/local-store.cc
+++ b/nix/libstore/local-store.cc
@@ -288,7 +288,17 @@ LocalStore::LocalStore(bool reserveSpace)
             struct stat st;
             if (stat(reservedPath.c_str(), &st) == -1 ||
                 st.st_size != settings.reservedSize)
-                writeFile(reservedPath, string(settings.reservedSize, 'X'));
+            {
+                AutoCloseFD fd = open(reservedPath.c_str(), O_WRONLY | O_CREAT, 0600);
+                int res = -1;
+#if HAVE_POSIX_FALLOCATE
+                res = posix_fallocate(fd, 0, settings.reservedSize);
+#endif
+                if (res == -1) {
+                    writeFull(fd, string(settings.reservedSize, 'X'));
+                    ftruncate(fd, settings.reservedSize);
+                }
+            }
         }
         else
             deletePath(reservedPath);