summaryrefslogtreecommitdiff
path: root/Source/Core/Common/FileUtil.cpp
diff options
context:
space:
mode:
authorOatmealDome <julian@oatmealdome.me>2022-07-05 15:13:20 -0400
committerOatmealDome <julian@oatmealdome.me>2022-07-05 15:13:20 -0400
commitc6eb5e2623f0f751dc9757bed1a99001cc3bce80 (patch)
tree519cd2b1c09ab5475a7dfd3125ddd877c45fe70e /Source/Core/Common/FileUtil.cpp
parent24498ca3159130eca123dc25ccae92781fdc3c34 (diff)
FileUtil: Only attempt to write to the destination in Copy if there is actually content to write
Diffstat (limited to 'Source/Core/Common/FileUtil.cpp')
-rw-r--r--Source/Core/Common/FileUtil.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp
index c9dae68b60..b03a22f108 100644
--- a/Source/Core/Common/FileUtil.cpp
+++ b/Source/Core/Common/FileUtil.cpp
@@ -433,8 +433,18 @@ bool Copy(const std::string& source_path, const std::string& destination_path)
#else
std::ifstream source{source_path, std::ios::binary};
std::ofstream destination{destination_path, std::ios::binary};
- destination << source.rdbuf();
- return source.good() && destination.good();
+
+ // Only attempt to write with << if there is actually something in the file
+ if (source.peek() != std::ifstream::traits_type::eof())
+ {
+ destination << source.rdbuf();
+ return source.good() && destination.good();
+ }
+ else
+ {
+ // We can't use source.good() here because eofbit will be set, so check for the other bits.
+ return !source.fail() && !source.bad() && destination.good();
+ }
#endif
}