Use posix_fallocate to create /nix/var/nix/db/reserved

This commit is contained in:
Eelco Dolstra 2015-06-22 15:54:55 +02:00 committed by Ludovic Courtès
parent 4e5ab98d6d
commit 5e0a9ae2e2
1 changed files with 11 additions and 1 deletions

View File

@ -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);