mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-24 14:59:44 -05:00
Fix broken safe saves across file systems
* Fix #2888 * Qt has an undocumented rename implementation for QTemporaryFile that does not fallback to the copy implementation. Forcing the use of QFile::rename(...) allows for this fallback and protects against cross-device link errors.
This commit is contained in:
parent
835e1b8787
commit
ec82931573
@ -241,20 +241,16 @@ bool Database::save(const QString& filePath, QString* error, bool atomic, bool b
|
||||
|
||||
// Delete the original db and move the temp file in place
|
||||
QFile::remove(filePath);
|
||||
#ifdef Q_OS_LINUX
|
||||
// workaround to make this workaround work, see: https://bugreports.qt.io/browse/QTBUG-64008
|
||||
if (tempFile.copy(filePath)) {
|
||||
// successfully saved database file
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
if (tempFile.rename(filePath)) {
|
||||
|
||||
// Note: call into the QFile rename instead of QTemporaryFile
|
||||
// due to an undocumented difference in how the function handles
|
||||
// errors. This prevents errors when saving across file systems.
|
||||
if (tempFile.QFile::rename(filePath)) {
|
||||
// successfully saved database file
|
||||
tempFile.setAutoRemove(false);
|
||||
setFilePath(filePath);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (error) {
|
||||
*error = tempFile.errorString();
|
||||
|
Loading…
Reference in New Issue
Block a user