Fix Backup on Save Mechanism (#2885)

Backup (aka. rename to `filename` + `~`) the filepath that
will be written to while saving.
Before the fix this was not always the case as non `.xopp`
extensions where overwritten to `.xopp` upon saving, but
only after the backup was already created for to original filepath.
upstream-master
idotobi 5 years ago committed by GitHub
parent 5e78a44f86
commit 814dd011f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/control/jobs/SaveJob.cpp

@ -90,9 +90,13 @@ auto SaveJob::save() -> bool {
fs::path const filepath = doc->getFilepath();
doc->unlock();
auto const target = fs::path{filepath}.replace_extension(".xopp");
if (doc->shouldCreateBackupOnSave()) {
try {
Util::safeRenameFile(filepath, fs::path{filepath} += "~");
// Note: The backup must be created for the target as this is the filepath
// which will be written to. Do not use the `filepath` variable!
Util::safeRenameFile(target, fs::path{target} += "~");
} catch (fs::filesystem_error const& fe) {
g_warning("Could not create backup! Failed with %s", fe.what());
return false;
@ -100,8 +104,6 @@ auto SaveJob::save() -> bool {
doc->setCreateBackupOnSave(false);
}
auto const target = fs::path{filepath}.replace_extension(".xopp");
doc->lock();
h.saveTo(target, this->control);
doc->setFilepath(target);

Loading…
Cancel
Save