diff options
Diffstat (limited to 'src/common/fs/file.cpp')
| -rw-r--r-- | src/common/fs/file.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/common/fs/file.cpp b/src/common/fs/file.cpp index 077f34995..274f57659 100644 --- a/src/common/fs/file.cpp +++ b/src/common/fs/file.cpp | |||
| @@ -306,9 +306,9 @@ bool IOFile::Flush() const { | |||
| 306 | errno = 0; | 306 | errno = 0; |
| 307 | 307 | ||
| 308 | #ifdef _WIN32 | 308 | #ifdef _WIN32 |
| 309 | const auto flush_result = std::fflush(file) == 0 && _commit(fileno(file)) == 0; | 309 | const auto flush_result = std::fflush(file) == 0; |
| 310 | #else | 310 | #else |
| 311 | const auto flush_result = std::fflush(file) == 0 && fsync(fileno(file)) == 0; | 311 | const auto flush_result = std::fflush(file) == 0; |
| 312 | #endif | 312 | #endif |
| 313 | 313 | ||
| 314 | if (!flush_result) { | 314 | if (!flush_result) { |
| @@ -320,6 +320,28 @@ bool IOFile::Flush() const { | |||
| 320 | return flush_result; | 320 | return flush_result; |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | bool IOFile::Commit() const { | ||
| 324 | if (!IsOpen()) { | ||
| 325 | return false; | ||
| 326 | } | ||
| 327 | |||
| 328 | errno = 0; | ||
| 329 | |||
| 330 | #ifdef _WIN32 | ||
| 331 | const auto commit_result = std::fflush(file) == 0 && _commit(fileno(file)) == 0; | ||
| 332 | #else | ||
| 333 | const auto commit_result = std::fflush(file) == 0 && fsync(fileno(file)) == 0; | ||
| 334 | #endif | ||
| 335 | |||
| 336 | if (!commit_result) { | ||
| 337 | const auto ec = std::error_code{errno, std::generic_category()}; | ||
| 338 | LOG_ERROR(Common_Filesystem, "Failed to commit the file at path={}, ec_message={}", | ||
| 339 | PathToUTF8String(file_path), ec.message()); | ||
| 340 | } | ||
| 341 | |||
| 342 | return commit_result; | ||
| 343 | } | ||
| 344 | |||
| 323 | bool IOFile::SetSize(u64 size) const { | 345 | bool IOFile::SetSize(u64 size) const { |
| 324 | if (!IsOpen()) { | 346 | if (!IsOpen()) { |
| 325 | return false; | 347 | return false; |
| @@ -347,6 +369,9 @@ u64 IOFile::GetSize() const { | |||
| 347 | return 0; | 369 | return 0; |
| 348 | } | 370 | } |
| 349 | 371 | ||
| 372 | // Flush any unwritten buffered data into the file prior to retrieving the file size. | ||
| 373 | std::fflush(file); | ||
| 374 | |||
| 350 | std::error_code ec; | 375 | std::error_code ec; |
| 351 | 376 | ||
| 352 | const auto file_size = fs::file_size(file_path, ec); | 377 | const auto file_size = fs::file_size(file_path, ec); |