diff options
Diffstat (limited to 'zenstore')
| -rw-r--r-- | zenstore/basicfile.cpp | 34 | ||||
| -rw-r--r-- | zenstore/gc.cpp | 10 |
2 files changed, 34 insertions, 10 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 } diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp index a86bae143..117fe3b49 100644 --- a/zenstore/gc.cpp +++ b/zenstore/gc.cpp @@ -123,18 +123,20 @@ namespace { { return zen::MakeErrorCodeFromLastError(); } - if (posix_fallocate(Fd, 0, (off_t)Size) < 0) + std::error_code Ec = posix_fallocate(Fd, 0, (off_t)Size); + if (Ec) { - return zen::MakeErrorCodeFromLastError(); + return Ec; } # else if (ftruncate64(Fd, (off64_t)Size) < 0) { return zen::MakeErrorCodeFromLastError(); } - if (posix_fallocate64(Fd, 0, (off64_t)Size) < 0) + std::error_code Ec = posix_fallocate64(Fd, 0, (off64_t)Size); + if (Ec) { - return zen::MakeErrorCodeFromLastError(); + return Ec; } # endif Keep = true; |