Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdaterCommon: Copy content file to a temporary file before renaming on macOS #10419

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions Source/Core/UpdaterCommon/UpdaterCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,19 @@ bool UpdateFiles(const std::vector<TodoList::UpdateOp>& to_update,
// Unfortunately, there is a quirk in the kernel with how it handles the cache: if the file is
// simply overwritten, the cache isn't invalidated and the old code signature is used to verify
// the new file. This causes macOS to kill the process with a code signing error. To workaround
// this, we use File::Rename() instead of File::Copy().
if (!File::Rename(temp_path + DIR_SEP + content_filename, path))
// this, we use File::Rename() instead of File::Copy(). However, this also means that if two
// files have the same hash, the first file will succeed, but the second file will fail because
// the source file no longer exists. To deal with this, we copy the content file to a temporary
// file and then rename the temporary file to the destination path.
const std::string temporary_file = temp_path + DIR_SEP + "temporary_file";
if (!File::Copy(temp_path + DIR_SEP + content_filename, temporary_file))
{
fprintf(log_fp, "Could not copy %s to %s.\n", content_filename.c_str(),
temporary_file.c_str());
return false;
}

if (!File::Rename(temporary_file, path))
#else
if (!File::Copy(temp_path + DIR_SEP + content_filename, path))
#endif
Expand Down