about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-06-22T13·54+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-06-22T13·54+0200
commit2bc9c84327839e73e2b47e71bdc9f111dd2fc425 (patch)
treed8ee17de76ff069ed103516da7086ca6f5377bbb /src
parentba63ec6f39d3d006b2058f41fe877dc17031c95c (diff)
Use posix_fallocate to create /nix/var/nix/db/reserved
Diffstat (limited to 'src')
-rw-r--r--src/libstore/local-store.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 1dcd7228f347..074c3394ffb1 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -289,7 +289,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);