diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-02-22 14:39:37 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-02-23 13:29:40 +0000 |
commit | 4942ea633b40809f285e6bbc45d0692207aa7686 (patch) | |
tree | d74de78d271e53f5c8e9a51c6e6eb3fb914001d8 | |
parent | 39d1c29532656b49cccd0854d55b211f81fce2d5 (diff) |
Qt Designer: Potential fix for errors running several instances on Windows
Qt Designer used an additional tmp directory under the backup directory
in which it wrote the backup files first and then copied them over
apparently in order to make it somewhat atomic operation.
Replace the mechanism by QSaveFile which should achieve the same.
Task-number: QTBUG-122616
Change-Id: If90e6b95431648adabc75c05676f45ac15703113
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
(cherry picked from commit 222dfe93a403427aa7e6b14b8f0558331d0215a7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/designer/src/designer/qdesigner_actions.cpp | 52 |
1 files changed, 13 insertions, 39 deletions
diff --git a/src/designer/src/designer/qdesigner_actions.cpp b/src/designer/src/designer/qdesigner_actions.cpp index c5841559b..e19573aa4 100644 --- a/src/designer/src/designer/qdesigner_actions.cpp +++ b/src/designer/src/designer/qdesigner_actions.cpp @@ -1047,7 +1047,6 @@ void QDesignerActions::backupForms() return; - QStringList tmpFiles; QMap<QString, QString> backupMap; QDir backupDir(m_backupPath); for (int i = 0; i < count; ++i) { @@ -1062,36 +1061,22 @@ void QDesignerActions::backupForms() backupMap.insert(fwn, formBackupName); - QFile file(formBackupName.replace(m_backupPath, m_backupTmpPath)); - if (file.open(QFile::WriteOnly)){ - const QByteArray utf8Array = formWindowContents(fw->editor(), backupDir); - if (file.write(utf8Array, utf8Array.size()) != utf8Array.size()) { - backupMap.remove(fwn); - qdesigner_internal::designerWarning(tr("The backup file %1 could not be written: %2"). - arg(QDir::toNativeSeparators(file.fileName()), - file.errorString())); - } else - tmpFiles.append(formBackupName); - - file.close(); + bool ok = false; + QSaveFile file(formBackupName); + if (file.open(QFile::WriteOnly)) { + file.write(formWindowContents(fw->editor(), backupDir)); + ok = file.commit(); } - } - if(!tmpFiles.isEmpty()) { - const QStringList backupFiles = backupDir.entryList(QDir::Files); - for (const QString &backupFile : backupFiles) - backupDir.remove(backupFile); - - for (const QString &tmpName : std::as_const(tmpFiles)) { - QString name(tmpName); - name.replace(m_backupTmpPath, m_backupPath); - QFile tmpFile(tmpName); - if (!tmpFile.copy(name)) - qdesigner_internal::designerWarning(tr("The backup file %1 could not be written.").arg(name)); - tmpFile.remove(); + if (!ok) { + backupMap.remove(fwn); + qdesigner_internal::designerWarning(tr("The backup file %1 could not be written: %2"). + arg(QDir::toNativeSeparators(file.fileName()), + file.errorString())); } + } + if (!backupMap.isEmpty()) m_settings.setBackup(backupMap); - } } static QString fixResourceFileBackupPath(const QDesignerFormWindowInterface *fwi, @@ -1173,15 +1158,11 @@ void QDesignerActions::setWindowListSeparatorVisible(bool visible) bool QDesignerActions::ensureBackupDirectories() { - if (m_backupPath.isEmpty()) { - // create names + if (m_backupPath.isEmpty()) // create names m_backupPath = qdesigner_internal::dataDirectory() + u"/backup"_s; - m_backupTmpPath = m_backupPath + u"/tmp"_s; - } // ensure directories const QDir backupDir(m_backupPath); - const QDir backupTmpDir(m_backupTmpPath); if (!backupDir.exists()) { if (!backupDir.mkpath(m_backupPath)) { @@ -1190,13 +1171,6 @@ bool QDesignerActions::ensureBackupDirectories() { return false; } } - if (!backupTmpDir.exists()) { - if (!backupTmpDir.mkpath(m_backupTmpPath)) { - qdesigner_internal::designerWarning(tr("The temporary backup directory %1 could not be created.") - .arg(QDir::toNativeSeparators(m_backupTmpPath))); - return false; - } - } return true; } |