-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Correct saving files to DropBox/Drive/OneDrive #1385
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
#include "core/Database.h" | ||
#include "core/Group.h" | ||
#include "core/Metadata.h" | ||
#include "core/AsyncTask.h" | ||
#include "format/CsvExporter.h" | ||
#include "gui/Clipboard.h" | ||
#include "gui/DatabaseWidget.h" | ||
|
@@ -43,6 +44,7 @@ DatabaseManagerStruct::DatabaseManagerStruct() | |
: dbWidget(nullptr) | ||
, modified(false) | ||
, readOnly(false) | ||
, saveAttempts(0) | ||
{ | ||
} | ||
|
||
|
@@ -322,12 +324,15 @@ bool DatabaseTabWidget::saveDatabase(Database* db, QString filePath) | |
} | ||
|
||
dbStruct.dbWidget->blockAutoReload(true); | ||
QString errorMessage = db->saveToFile(filePath); | ||
// TODO: Make this async, but lock out the database widget to prevent re-entrance | ||
bool useAtomicSaves = config()->get("UseAtomicSaves", true).toBool(); | ||
QString errorMessage = db->saveToFile(filePath, useAtomicSaves, config()->get("BackupBeforeSave").toBool()); | ||
dbStruct.dbWidget->blockAutoReload(false); | ||
|
||
if (errorMessage.isEmpty()) { | ||
// successfully saved database file | ||
dbStruct.modified = false; | ||
dbStruct.saveAttempts = 0; | ||
dbStruct.fileInfo = QFileInfo(filePath); | ||
dbStruct.dbWidget->databaseSaved(); | ||
updateTabName(db); | ||
|
@@ -336,6 +341,22 @@ bool DatabaseTabWidget::saveDatabase(Database* db, QString filePath) | |
} else { | ||
dbStruct.modified = true; | ||
updateTabName(db); | ||
|
||
if (++dbStruct.saveAttempts > 2 && useAtomicSaves) { | ||
// Saving failed 3 times, issue a warning and attempt to resolve | ||
auto choice = MessageBox::question(this, tr("Disable safe saves?"), | ||
tr("KeePassXC has failed to save the database multiple times. " | ||
"This is likely caused by file sync services holding a lock on " | ||
"the save file.\nDisable safe saves and try again?"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @droidmonkey shouldn't we also use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking that, too. But I don't know how well users will understand it. Atomic in a non-nuclear context is a very domain-specific word. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Atomic is a developer term. I wanted to dumb it down on the user interface. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User (me) googled it: "write to tmp-file and then (atomic->) move over". (had no idea before searching for the term - sounded a little intimidating to me :) X Atomic save (write temporary file - on success secure replace original with it) |
||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); | ||
if (choice == QMessageBox::Yes) { | ||
config()->set("UseAtomicSaves", false); | ||
return saveDatabase(db, filePath); | ||
} | ||
// Reset save attempts without changing anything | ||
dbStruct.saveAttempts = 0; | ||
} | ||
|
||
emit messageTab(tr("Writing the database failed.").append("\n").append(errorMessage), | ||
MessageWidget::Error); | ||
return false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would check for write permissions first and show a dedicated error message. Otherwise the user will disable atomic saves for nothing if the problem is actually missing write permissions.
I know this is an edge case, because without write permissions, the DB will be opened in read-only mode, but it can still occur if write permissions are somehow removed mid-air.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't easily check for write conditions at the directory level on windows. I did a fair bit of research on the matter while trying to diagnose. The only edge case that the read-only open fails at is opening a writable file in a non writable directory. That doesnt seem like a common scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, leave as is then.