Move project save commit planning to app core
This commit is contained in:
@@ -2541,33 +2541,39 @@ bool Canvas::project_save_thread(std::string file_path, bool show_progress)
|
||||
|
||||
fclose(fp);
|
||||
|
||||
bool success = false;
|
||||
bool target_remove_attempted = false;
|
||||
bool target_remove_succeeded = false;
|
||||
bool temporary_rename_attempted = false;
|
||||
bool temporary_rename_succeeded = false;
|
||||
if (use_tmp)
|
||||
{
|
||||
LOG("project saved tmp to %s", tmp_path.c_str());
|
||||
LOG("swapping to %s", file_path.c_str());
|
||||
if (std::remove(file_path.c_str()) == 0)
|
||||
target_remove_attempted = true;
|
||||
target_remove_succeeded = std::remove(file_path.c_str()) == 0;
|
||||
if (target_remove_succeeded)
|
||||
{
|
||||
if (std::rename(tmp_path.c_str(), file_path.c_str()) == 0)
|
||||
{
|
||||
success = true;
|
||||
LOG("tmp file swapped succesfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
LOG("tmp file NOT swapped, original removed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
LOG("could not remove %s", file_path.c_str());
|
||||
temporary_rename_attempted = true;
|
||||
temporary_rename_succeeded = std::rename(tmp_path.c_str(), file_path.c_str()) == 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
|
||||
const auto commit_plan = pp::app::plan_document_canvas_project_save_commit(
|
||||
pp::app::DocumentCanvasProjectSaveCommitInput {
|
||||
.used_temporary = use_tmp,
|
||||
.target_remove_attempted = target_remove_attempted,
|
||||
.target_remove_succeeded = target_remove_succeeded,
|
||||
.temporary_rename_attempted = temporary_rename_attempted,
|
||||
.temporary_rename_succeeded = temporary_rename_succeeded,
|
||||
});
|
||||
const bool success = commit_plan.saved;
|
||||
if (commit_plan.saved && commit_plan.temporary_renamed) {
|
||||
LOG("tmp file swapped succesfully");
|
||||
} else if (!commit_plan.saved && commit_plan.target_may_be_missing) {
|
||||
LOG("tmp file NOT swapped, original removed");
|
||||
} else if (!commit_plan.saved && commit_plan.used_temporary) {
|
||||
LOG("could not remove %s", file_path.c_str());
|
||||
} else if (commit_plan.saved) {
|
||||
LOG("project saved to %s", file_path.c_str());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user