mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-13 08:19:50 -05:00
Improve handling of read-only files (#3408)
* Fix #3407 * Read-only files now disable auto-save and show as modified correctly. This allows the GUI to prompt to "save-as" instead of silently discarding changes when the read-only database is locked or closed.
This commit is contained in:
parent
3b330ee2d1
commit
2aac83d03b
@ -202,8 +202,12 @@ bool Database::save(QString* error, bool atomic, bool backup)
|
||||
*/
|
||||
bool Database::save(const QString& filePath, QString* error, bool atomic, bool backup)
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
if (m_data.isReadOnly) {
|
||||
// Disallow saving to the same file if read-only
|
||||
if (m_data.isReadOnly && filePath == m_data.filePath) {
|
||||
Q_ASSERT_X(false, "Database::save", "Could not save, database file is read-only.");
|
||||
if (error) {
|
||||
*error = tr("Could not save, database file is read-only.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -741,10 +745,6 @@ bool Database::isModified() const
|
||||
|
||||
void Database::markAsModified()
|
||||
{
|
||||
if (isReadOnly()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_modified = true;
|
||||
if (m_emitModified) {
|
||||
startModifiedTimer();
|
||||
@ -780,8 +780,6 @@ Database* Database::databaseByFilePath(const QString& filePath)
|
||||
|
||||
void Database::startModifiedTimer()
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
|
||||
if (!m_emitModified) {
|
||||
return;
|
||||
}
|
||||
|
@ -984,7 +984,10 @@ void DatabaseWidget::unlockDatabase(bool accepted)
|
||||
}
|
||||
replaceDatabase(db);
|
||||
if (db->isReadOnly()) {
|
||||
showMessage(tr("File opened in read only mode."), MessageWidget::Warning, false, -1);
|
||||
showMessage(tr("This database is opened in read-only mode. Autosave is disabled."),
|
||||
MessageWidget::Warning,
|
||||
false,
|
||||
-1);
|
||||
}
|
||||
|
||||
restoreGroupEntryFocus(m_groupBeforeLock, m_entryBeforeLock);
|
||||
@ -1225,7 +1228,7 @@ void DatabaseWidget::onGroupChanged(Group* group)
|
||||
|
||||
void DatabaseWidget::onDatabaseModified()
|
||||
{
|
||||
if (!m_blockAutoSave && config()->get("AutoSaveAfterEveryChange").toBool()) {
|
||||
if (!m_blockAutoSave && config()->get("AutoSaveAfterEveryChange").toBool() && !m_db->isReadOnly()) {
|
||||
save();
|
||||
} else {
|
||||
// Only block once, then reset
|
||||
|
Loading…
Reference in New Issue
Block a user