Handle ftruncate failures

This commit is contained in:
Thomas Goyne 2014-05-20 06:58:08 -07:00
parent c2455cccb6
commit 291437eed6
1 changed files with 9 additions and 1 deletions

View File

@ -147,8 +147,16 @@ temp_file_mapping::temp_file_mapping(fs::path const& filename, uint64_t size)
SetFilePointerEx(handle, li, nullptr, FILE_BEGIN); SetFilePointerEx(handle, li, nullptr, FILE_BEGIN);
SetEndOfFile(handle); SetEndOfFile(handle);
#else #else
ftruncate(handle, size);
unlink(filename.string().c_str()); unlink(filename.string().c_str());
if (ftruncate(handle, size) == -1) {
switch (errno) {
case EBADF: throw InternalError("Error opening file " + filename.string() + " not handled", nullptr);
case EFBIG: throw fs::DriveFull(filename);
case EINVAL: throw InternalError("File opened incorrectly: " + filename.string(), nullptr);
case EROFS: throw fs::WriteDenied(filename);
default: throw fs::FileSystemUnknownError("Unknown error opening file: " + filename.string());
}
}
#endif #endif
} }