mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Fix db history when adding new db (#9022)
Fixes https://github.com/keepassxreboot/keepassxc/issues/8375
This commit is contained in:
parent
93831f64a3
commit
8846880015
@ -275,8 +275,8 @@ bool Database::saveAs(const QString& filePath, SaveAction action, const QString&
|
||||
bool isNewFile = !QFile::exists(realFilePath);
|
||||
bool ok = AsyncTask::runAndWaitForFuture([&] { return performSave(realFilePath, action, backupFilePath, error); });
|
||||
if (ok) {
|
||||
markAsClean();
|
||||
setFilePath(filePath);
|
||||
markAsClean();
|
||||
if (isNewFile) {
|
||||
QFile::setPermissions(realFilePath, QFile::ReadUser | QFile::WriteUser);
|
||||
}
|
||||
|
@ -244,6 +244,7 @@ void DatabaseTabWidget::addDatabaseTab(DatabaseWidget* dbWidget, bool inBackgrou
|
||||
SLOT(updateTabName()));
|
||||
connect(dbWidget, SIGNAL(databaseModified()), SLOT(updateTabName()));
|
||||
connect(dbWidget, SIGNAL(databaseSaved()), SLOT(updateTabName()));
|
||||
connect(dbWidget, SIGNAL(databaseSaved()), SLOT(updateLastDatabases()));
|
||||
connect(dbWidget, SIGNAL(databaseUnlocked()), SLOT(updateTabName()));
|
||||
connect(dbWidget, SIGNAL(databaseUnlocked()), SLOT(emitDatabaseLockChanged()));
|
||||
connect(dbWidget, SIGNAL(databaseLocked()), SLOT(updateTabName()));
|
||||
@ -829,6 +830,18 @@ void DatabaseTabWidget::updateLastDatabases(const QString& filename)
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseTabWidget::updateLastDatabases()
|
||||
{
|
||||
auto dbWidget = currentDatabaseWidget();
|
||||
|
||||
if (dbWidget) {
|
||||
auto filePath = dbWidget->database()->filePath();
|
||||
if (!filePath.isEmpty()) {
|
||||
updateLastDatabases(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseTabWidget::emitActiveDatabaseChanged()
|
||||
{
|
||||
emit activeDatabaseChanged(currentDatabaseWidget());
|
||||
|
@ -105,6 +105,7 @@ private slots:
|
||||
void emitDatabaseLockChanged();
|
||||
void handleDatabaseUnlockDialogFinished(bool accepted, DatabaseWidget* dbWidget);
|
||||
void handleExportError(const QString& reason);
|
||||
void updateLastDatabases();
|
||||
|
||||
private:
|
||||
QSharedPointer<Database> execNewDatabaseWizard();
|
||||
|
@ -99,6 +99,34 @@ void TestDatabase::testSave()
|
||||
QVERIFY(!QFile::exists(backupFilePath));
|
||||
}
|
||||
|
||||
void TestDatabase::testSaveAs()
|
||||
{
|
||||
TemporaryFile tempFile;
|
||||
QVERIFY(tempFile.copyFromFile(dbFileName));
|
||||
|
||||
auto db = QSharedPointer<Database>::create();
|
||||
auto key = QSharedPointer<CompositeKey>::create();
|
||||
key->addKey(QSharedPointer<PasswordKey>::create("a"));
|
||||
|
||||
QString error;
|
||||
QVERIFY(db->open(tempFile.fileName(), key, &error));
|
||||
|
||||
// Happy path case when try to save as new DB.
|
||||
QSignalSpy spyFilePathChanged(db.data(), SIGNAL(filePathChanged(const QString&, const QString&)));
|
||||
QString newDbFileName = QStringLiteral(KEEPASSX_TEST_DATA_DIR).append("/SaveAsNewDatabase.kdbx");
|
||||
QVERIFY2(db->saveAs(newDbFileName, Database::Atomic, QString(), &error), error.toLatin1());
|
||||
QVERIFY(!db->isModified());
|
||||
QCOMPARE(spyFilePathChanged.count(), 1);
|
||||
QVERIFY(QFile::exists(newDbFileName));
|
||||
QFile::remove(newDbFileName);
|
||||
QVERIFY(!QFile::exists(newDbFileName));
|
||||
|
||||
// Negative case when try to save not initialized DB.
|
||||
db->releaseData();
|
||||
QVERIFY2(!db->saveAs(newDbFileName, Database::Atomic, QString(), &error), error.toLatin1());
|
||||
QCOMPARE(error, QString("Could not save, database has not been initialized!"));
|
||||
}
|
||||
|
||||
void TestDatabase::testSignals()
|
||||
{
|
||||
TemporaryFile tempFile;
|
||||
|
@ -29,6 +29,7 @@ private slots:
|
||||
void initTestCase();
|
||||
void testOpen();
|
||||
void testSave();
|
||||
void testSaveAs();
|
||||
void testSignals();
|
||||
void testEmptyRecycleBinOnDisabled();
|
||||
void testEmptyRecycleBinOnNotCreated();
|
||||
|
Loading…
Reference in New Issue
Block a user