Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JMC47 committed Jul 5, 2022
2 parents c3b7019 + c6eb5e2 commit 3cd82b6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Source/Core/Common/FileUtil.cpp
Expand Up @@ -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
}

Expand Down

0 comments on commit 3cd82b6

Please sign in to comment.