Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Geyer <debfx@fobos.de>2015-07-19 01:41:35 +0300
committerFelix Geyer <debfx@fobos.de>2015-07-19 01:41:35 +0300
commit7d3fb58cf586e56d881b2592f0b0f07df215575e (patch)
tree5aa5ade42b84355e5813a3ad8dee4b2de63ecc99
parentdf5da2fcef128f35fad0c26a6d692bf581bf203c (diff)
Fix lock file location in saveDatabaseAs().2.0-beta1
Previously the directory of the lock file path was empty when saving to a new file. saveFile.open() doesn't create the file and canonicalPath() only works when the file exists.
-rw-r--r--src/gui/DatabaseTabWidget.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp
index 3f4cbcf42..8964d98cf 100644
--- a/src/gui/DatabaseTabWidget.cpp
+++ b/src/gui/DatabaseTabWidget.cpp
@@ -329,15 +329,16 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
QString fileName = fileDialog()->getSaveFileName(this, tr("Save database as"),
oldFileName, tr("KeePass 2 Database").append(" (*.kdbx)"));
if (!fileName.isEmpty()) {
- QSaveFile saveFile(fileName);
- if (!saveFile.open(QIODevice::WriteOnly)) {
- MessageBox::critical(this, tr("Error"), tr("Writing the database failed.") + "\n\n"
- + saveFile.errorString());
- return false;
- }
-
QFileInfo fileInfo(fileName);
- QString lockFileName = QString("%1/.%2.lock").arg(fileInfo.canonicalPath(), fileInfo.fileName());
+ QString lockFilePath;
+ if (fileInfo.exists()) {
+ // returns empty string when file doesn't exist
+ lockFilePath = fileInfo.canonicalPath();
+ }
+ else {
+ lockFilePath = fileInfo.absolutePath();
+ }
+ QString lockFileName = QString("%1/.%2.lock").arg(lockFilePath, fileInfo.fileName());
QScopedPointer<QLockFile> lockFile(new QLockFile(lockFileName));
lockFile->setStaleLockTime(0);
if (!lockFile->tryLock()) {
@@ -361,6 +362,13 @@ bool DatabaseTabWidget::saveDatabaseAs(Database* db)
}
}
+ QSaveFile saveFile(fileName);
+ if (!saveFile.open(QIODevice::WriteOnly)) {
+ MessageBox::critical(this, tr("Error"), tr("Writing the database failed.") + "\n\n"
+ + saveFile.errorString());
+ return false;
+ }
+
m_writer.writeDatabase(&saveFile, db);
if (!saveFile.commit()) {
MessageBox::critical(this, tr("Error"), tr("Writing the database failed.") + "\n\n"