diff options
author | bunnei <bunneidev@gmail.com> | 2021-07-07 09:40:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-07 09:40:31 +0200 |
commit | 2eb018c80fd2a83686ee11a80c7427a98ea44354 (patch) | |
tree | a062eae0798d08a88411642490c2fef96b082dc6 /src/common/fs/file.cpp | |
parent | Merge pull request #6497 from FernandoS27/scotty-doesnt-know (diff) | |
parent | common: logging: backend: Close the file after exceeding the write limit (diff) | |
download | yuzu-2eb018c80fd2a83686ee11a80c7427a98ea44354.tar yuzu-2eb018c80fd2a83686ee11a80c7427a98ea44354.tar.gz yuzu-2eb018c80fd2a83686ee11a80c7427a98ea44354.tar.bz2 yuzu-2eb018c80fd2a83686ee11a80c7427a98ea44354.tar.lz yuzu-2eb018c80fd2a83686ee11a80c7427a98ea44354.tar.xz yuzu-2eb018c80fd2a83686ee11a80c7427a98ea44354.tar.zst yuzu-2eb018c80fd2a83686ee11a80c7427a98ea44354.zip |
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 { errno = 0; #ifdef _WIN32 - const auto flush_result = std::fflush(file) == 0 && _commit(fileno(file)) == 0; + const auto flush_result = std::fflush(file) == 0; #else - const auto flush_result = std::fflush(file) == 0 && fsync(fileno(file)) == 0; + const auto flush_result = std::fflush(file) == 0; #endif if (!flush_result) { @@ -320,6 +320,28 @@ bool IOFile::Flush() const { return flush_result; } +bool IOFile::Commit() const { + if (!IsOpen()) { + return false; + } + + errno = 0; + +#ifdef _WIN32 + const auto commit_result = std::fflush(file) == 0 && _commit(fileno(file)) == 0; +#else + const auto commit_result = std::fflush(file) == 0 && fsync(fileno(file)) == 0; +#endif + + if (!commit_result) { + const auto ec = std::error_code{errno, std::generic_category()}; + LOG_ERROR(Common_Filesystem, "Failed to commit the file at path={}, ec_message={}", + PathToUTF8String(file_path), ec.message()); + } + + return commit_result; +} + bool IOFile::SetSize(u64 size) const { if (!IsOpen()) { return false; @@ -347,6 +369,9 @@ u64 IOFile::GetSize() const { return 0; } + // Flush any unwritten buffered data into the file prior to retrieving the file size. + std::fflush(file); + std::error_code ec; const auto file_size = fs::file_size(file_path, ec); |