aboutsummaryrefslogtreecommitdiff
path: root/zenstore/basicfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zenstore/basicfile.cpp')
-rw-r--r--zenstore/basicfile.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp
index 8b3ee2844..eb93638f2 100644
--- a/zenstore/basicfile.cpp
+++ b/zenstore/basicfile.cpp
@@ -324,16 +324,38 @@ BasicFile::SetFileSize(uint64_t FileSize)
#if ZEN_PLATFORM_WINDOWS
LARGE_INTEGER liFileSize;
liFileSize.QuadPart = FileSize;
- ::SetFilePointerEx(m_FileHandle, liFileSize, 0, FILE_BEGIN);
- ::SetEndOfFile(m_FileHandle);
+ BOOL OK = ::SetFilePointerEx(m_FileHandle, liFileSize, 0, FILE_BEGIN);
+ if (OK == FALSE)
+ {
+ ThrowLastError(fmt::format("Failed to set file pointer to {} for file {}", FileSize, PathFromHandle(m_FileHandle)));
+ }
+ OK = ::SetEndOfFile(m_FileHandle);
+ if (OK == FALSE)
+ {
+ ThrowLastError(fmt::format("Failed to set end of file to {} for file {}", FileSize, PathFromHandle(m_FileHandle)));
+ }
#elif ZEN_PLATFORM_MAC
int Fd = int(intptr_t(m_FileHandle));
- ftruncate(Fd, (off_t)FileSize);
- posix_fallocate(Fd, 0, (off_t)FileSize);
+ if (ftruncate(Fd, (off_t)FileSize) < 0)
+ {
+ ThrowLastError(fmt::format("Failed to set truncate file to {} for file {}", FileSize, PathFromHandle(m_FileHandle)));
+ }
+ std::error_code Ec = posix_fallocate(Fd, 0, (off_t)FileSize);
+ if (Ec)
+ {
+ ThrowSystemError(Ec, fmt::format("Failed to allocate space of {} for file {}", FileSize, PathFromHandle(m_FileHandle)))
+ }
#else
int Fd = int(intptr_t(m_FileHandle));
- ftruncate64(Fd, (off64_t)FileSize);
- posix_fallocate64(Fd, 0, (off64_t)FileSize);
+ if (ftruncate64(Fd, (off64_t)FileSize) < 0)
+ {
+ ThrowLastError(fmt::format("Failed to set truncate file to {} for file {}", FileSize, PathFromHandle(m_FileHandle)));
+ }
+ std::error_code Ec = posix_fallocate64(Fd, 0, (off64_t)FileSize);
+ if (Ec)
+ {
+ ThrowSystemError(Ec, fmt::format("Failed to allocate space of {} for file {}", FileSize, PathFromHandle(m_FileHandle)))
+ }
#endif
}