summaryrefslogtreecommitdiffstats
path: root/src/designer
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-22 14:39:37 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-23 08:31:15 +0100
commit222dfe93a403427aa7e6b14b8f0558331d0215a7 (patch)
tree443799f4b8dc6f850ef792e4f7bf57f0643954db /src/designer
parent6f8d951e022722cdeb5e913b0564891b5042cfa7 (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 Pick-to: 6.7 Change-Id: If90e6b95431648adabc75c05676f45ac15703113 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/designer')
-rw-r--r--src/designer/src/designer/qdesigner_actions.cpp52
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 ace227048..065e543e9 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;
}