aboutsummaryrefslogtreecommitdiff
path: root/zenstore/basicfile.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-04-02 00:19:24 +0200
committerDan Engelbrecht <[email protected]>2022-04-02 00:19:24 +0200
commit65a1ec5ba5d58eaa8929e126fca12c1c00d69edf (patch)
treeeeb78c5a382ac7c67e0ec5d37e2f8f3aec6bad81 /zenstore/basicfile.cpp
parentmore linux fixes (diff)
downloadzen-65a1ec5ba5d58eaa8929e126fca12c1c00d69edf.tar.xz
zen-65a1ec5ba5d58eaa8929e126fca12c1c00d69edf.zip
don't try to allocate file space for a zero size file
Diffstat (limited to 'zenstore/basicfile.cpp')
-rw-r--r--zenstore/basicfile.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp
index 6e60c6e9c..e795b67eb 100644
--- a/zenstore/basicfile.cpp
+++ b/zenstore/basicfile.cpp
@@ -352,10 +352,13 @@ BasicFile::SetFileSize(uint64_t FileSize)
ThrowSystemError(Error, fmt::format("Failed to set truncate file to {} for file {}", FileSize, PathFromHandle(m_FileHandle)));
}
}
- int Error = posix_fallocate(Fd, 0, (off_t)FileSize);
- if (Error)
+ if (FileSize > 0)
{
- ThrowSystemError(Error, fmt::format("Failed to allocate space of {} for file {}", FileSize, PathFromHandle(m_FileHandle)))
+ int Error = posix_fallocate(Fd, 0, (off_t)FileSize);
+ if (Error)
+ {
+ ThrowSystemError(Error, fmt::format("Failed to allocate space of {} for file {}", FileSize, PathFromHandle(m_FileHandle)));
+ }
}
#else
int Fd = int(intptr_t(m_FileHandle));
@@ -367,10 +370,13 @@ BasicFile::SetFileSize(uint64_t FileSize)
ThrowSystemError(Error, fmt::format("Failed to set truncate file to {} for file {}", FileSize, PathFromHandle(m_FileHandle)));
}
}
- int Error = posix_fallocate64(Fd, 0, (off64_t)FileSize);
- if (Error)
+ if (FileSize > 0)
{
- ThrowSystemError(Error, fmt::format("Failed to allocate space of {} for file {}", FileSize, PathFromHandle(m_FileHandle)))
+ int Error = posix_fallocate64(Fd, 0, (off64_t)FileSize);
+ if (Error)
+ {
+ ThrowSystemError(Error, fmt::format("Failed to allocate space of {} for file {}", FileSize, PathFromHandle(m_FileHandle)));
+ }
}
#endif
}