Merge pull request #10810 from OatmealDome/fileutil-copy-mac-updater

FileUtil: Only attempt to write to the destination in Copy if there is actually content to write
This commit is contained in:
JMC47 2022-07-05 18:08:00 -04:00 committed by GitHub
commit 3cd82b6193
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -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
}