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:
commit
3cd82b6193
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue