From 2bc9c84327839e73e2b47e71bdc9f111dd2fc425 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 22 Jun 2015 15:54:55 +0200 Subject: Use posix_fallocate to create /nix/var/nix/db/reserved --- src/libstore/local-store.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/libstore/local-store.cc') diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 1dcd7228f..074c3394f 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); -- cgit v1.2.3