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 committed by GitHub
parent 6acd0b25ae
commit 33bf6eb892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -283,6 +283,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)) {
@ -295,6 +300,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;
@ -329,6 +339,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