Skip to content
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

Prevent infinite save loop when location is unavailable #3026

Merged
merged 1 commit into from
Apr 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,9 +1158,10 @@ void DatabaseWidget::onDatabaseModified()
{
if (!m_blockAutoSave && config()->get("AutoSaveAfterEveryChange").toBool()) {
save();
} else {
// Only block once, then reset
m_blockAutoSave = false;
}

m_blockAutoSave = false;
}

QString DatabaseWidget::getCurrentSearch()
Expand Down Expand Up @@ -1258,11 +1259,13 @@ bool DatabaseWidget::lock()
}

if (m_db->isModified()) {
bool saved = false;
// Attempt to save on exit, but don't block locking if it fails
if (config()->get("AutoSaveOnExit").toBool()) {
if (!save()) {
return false;
}
} else {
saved = save();
}

if (!saved) {
QString msg;
if (!m_db->metadata()->name().toHtmlEscaped().isEmpty()) {
msg = tr("\"%1\" was modified.\nSave changes?").arg(m_db->metadata()->name().toHtmlEscaped());
Expand Down Expand Up @@ -1521,11 +1524,14 @@ bool DatabaseWidget::save()
return true;
}

// Read-only and new databases ask for filename
if (m_db->isReadOnly() || m_db->filePath().isEmpty()) {
return saveAs();
}

// Prevent recursions and infinite save loops
blockAutoReload(true);
m_blockAutoSave = true;
++m_saveAttempts;

// TODO: Make this async, but lock out the database widget to prevent re-entrance
Expand All @@ -1536,6 +1542,7 @@ bool DatabaseWidget::save()

if (ok) {
m_saveAttempts = 0;
m_blockAutoSave = false;
return true;
}

Expand Down