From 923091b4ab810215cdf43e7bbde4e10608962e7e Mon Sep 17 00:00:00 2001 From: Vasilito Date: Thu, 7 May 2026 08:16:32 +0100 Subject: [PATCH] fix: handle KF6 Parts temporary file failures --- .../kde/kf6-parts/source/src/readonlypart.cpp | 6 +++- .../kf6-parts/source/src/readwritepart.cpp | 29 +++++++++++++++---- .../kf6-parts/source/src/readwritepart_p.h | 2 +- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/local/recipes/kde/kf6-parts/source/src/readonlypart.cpp b/local/recipes/kde/kf6-parts/source/src/readonlypart.cpp index 4b4a58cce..2cfa51d82 100644 --- a/local/recipes/kde/kf6-parts/source/src/readonlypart.cpp +++ b/local/recipes/kde/kf6-parts/source/src/readonlypart.cpp @@ -178,7 +178,11 @@ void ReadOnlyPartPrivate::openRemoteFile() } QTemporaryFile tempFile(QDir::tempPath() + QLatin1Char('/') + m_metaData.pluginId() + QLatin1String("XXXXXX") + extension); tempFile.setAutoRemove(false); - tempFile.open(); + if (!tempFile.open()) { + qCWarning(KPARTSLOG) << "Could not create temporary file for remote open:" << tempFile.errorString(); + Q_EMIT q->canceled(QString()); + return; + } m_file = tempFile.fileName(); QUrl destURL = QUrl::fromLocalFile(m_file); diff --git a/local/recipes/kde/kf6-parts/source/src/readwritepart.cpp b/local/recipes/kde/kf6-parts/source/src/readwritepart.cpp index d585ccdb7..0fe289a8d 100644 --- a/local/recipes/kde/kf6-parts/source/src/readwritepart.cpp +++ b/local/recipes/kde/kf6-parts/source/src/readwritepart.cpp @@ -148,7 +148,10 @@ bool ReadWritePart::save() d->m_saveOk = false; if (d->m_file.isEmpty()) { // document was created empty - d->prepareSaving(); + if (!d->prepareSaving()) { + Q_EMIT canceled(QString()); + return false; + } } if (saveFile()) { return saveToUrl(); @@ -170,7 +173,14 @@ bool ReadWritePart::saveAs(const QUrl &url) d->m_originalURL = d->m_url; d->m_originalFilePath = d->m_file; d->m_url = url; // Store where to upload in saveToURL - d->prepareSaving(); + if (!d->prepareSaving()) { + d->m_url = d->m_originalURL; + d->m_file = d->m_originalFilePath; + d->m_duringSaveAs = false; + d->m_originalURL = QUrl(); + d->m_originalFilePath.clear(); + return false; + } bool result = save(); // Save local file and upload local file if (result) { if (d->m_originalURL != d->m_url) { @@ -190,7 +200,7 @@ bool ReadWritePart::saveAs(const QUrl &url) } // Set m_file correctly for m_url -void ReadWritePartPrivate::prepareSaving() +bool ReadWritePartPrivate::prepareSaving() { // Local file if (m_url.isLocalFile()) { @@ -200,17 +210,22 @@ void ReadWritePartPrivate::prepareSaving() m_bTemp = false; } m_file = m_url.toLocalFile(); + return true; } else { // Remote file // We haven't saved yet, or we did but locally - provide a temp file if (m_file.isEmpty() || !m_bTemp) { QTemporaryFile tempFile; tempFile.setAutoRemove(false); - tempFile.open(); + if (!tempFile.open()) { + qCWarning(KPARTSLOG) << "Could not create temporary file for remote save:" << tempFile.errorString(); + return false; + } m_file = tempFile.fileName(); m_bTemp = true; } // otherwise, we already had a temp file + return true; } } @@ -244,7 +259,11 @@ bool ReadWritePart::saveToUrl() d->m_uploadJob = nullptr; } QTemporaryFile *tempFile = new QTemporaryFile(); - tempFile->open(); + if (!tempFile->open()) { + qCWarning(KPARTSLOG) << "Could not create upload temporary file:" << tempFile->errorString(); + delete tempFile; + return false; + } QString uploadFile = tempFile->fileName(); delete tempFile; QUrl uploadUrl = QUrl::fromLocalFile(uploadFile); diff --git a/local/recipes/kde/kf6-parts/source/src/readwritepart_p.h b/local/recipes/kde/kf6-parts/source/src/readwritepart_p.h index 563325498..655624c81 100644 --- a/local/recipes/kde/kf6-parts/source/src/readwritepart_p.h +++ b/local/recipes/kde/kf6-parts/source/src/readwritepart_p.h @@ -31,7 +31,7 @@ public: void slotUploadFinished(KJob *job); - void prepareSaving(); + bool prepareSaving(); bool m_bModified; bool m_bReadWrite;