Retain file creation time when saving database (#6576)

* Fix #6028
This commit is contained in:
Jonathan White 2021-05-31 22:22:50 -04:00
parent 2a02242d44
commit 5cfbde0bb7
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01

View file

@ -272,6 +272,11 @@ bool Database::saveAs(const QString& filePath, QString* error, bool atomic, bool
bool Database::performSave(const QString& filePath, QString* error, bool atomic, bool backup)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
QFileInfo info(filePath);
auto createTime = info.exists() ? info.birthTime() : QDateTime::currentDateTime();
#endif
if (atomic) {
QSaveFile saveFile(filePath);
if (saveFile.open(QIODevice::WriteOnly)) {
@ -284,6 +289,11 @@ bool Database::performSave(const QString& filePath, QString* error, bool atomic,
backupDatabase(filePath);
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// Retain orginal creation time
saveFile.setFileTime(createTime, QFile::FileBirthTime);
#endif
if (saveFile.commit()) {
// successfully saved database file
return true;
@ -318,6 +328,10 @@ bool Database::performSave(const QString& filePath, QString* error, bool atomic,
// successfully saved the database
tempFile.setAutoRemove(false);
QFile::setPermissions(filePath, perms);
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// Retain orginal creation time
tempFile.setFileTime(createTime, QFile::FileBirthTime);
#endif
return true;
} else if (!backup || !restoreDatabase(filePath)) {
// Failed to copy new database in place, and