diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2021-07-05 18:32:14 +0200 |
---|---|---|
committer | Morph <39850852+Morph1984@users.noreply.github.com> | 2021-07-06 11:59:47 +0200 |
commit | 14ab50defb2c6b06aec9a1401154fc57e662fc9d (patch) | |
tree | 8fd09e89becca011840721de00e385318d597d96 /src/common/fs/file.cpp | |
parent | common: fs: file: Flush the file in GetSize (diff) | |
download | yuzu-14ab50defb2c6b06aec9a1401154fc57e662fc9d.tar yuzu-14ab50defb2c6b06aec9a1401154fc57e662fc9d.tar.gz yuzu-14ab50defb2c6b06aec9a1401154fc57e662fc9d.tar.bz2 yuzu-14ab50defb2c6b06aec9a1401154fc57e662fc9d.tar.lz yuzu-14ab50defb2c6b06aec9a1401154fc57e662fc9d.tar.xz yuzu-14ab50defb2c6b06aec9a1401154fc57e662fc9d.tar.zst yuzu-14ab50defb2c6b06aec9a1401154fc57e662fc9d.zip |
Diffstat (limited to 'src/common/fs/file.cpp')
-rw-r--r-- | src/common/fs/file.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/common/fs/file.cpp b/src/common/fs/file.cpp index 022780e4e..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; |