fix: handle KF6 Parts temporary file failures
This commit is contained in:
@@ -178,7 +178,11 @@ void ReadOnlyPartPrivate::openRemoteFile()
|
|||||||
}
|
}
|
||||||
QTemporaryFile tempFile(QDir::tempPath() + QLatin1Char('/') + m_metaData.pluginId() + QLatin1String("XXXXXX") + extension);
|
QTemporaryFile tempFile(QDir::tempPath() + QLatin1Char('/') + m_metaData.pluginId() + QLatin1String("XXXXXX") + extension);
|
||||||
tempFile.setAutoRemove(false);
|
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();
|
m_file = tempFile.fileName();
|
||||||
|
|
||||||
QUrl destURL = QUrl::fromLocalFile(m_file);
|
QUrl destURL = QUrl::fromLocalFile(m_file);
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ bool ReadWritePart::save()
|
|||||||
|
|
||||||
d->m_saveOk = false;
|
d->m_saveOk = false;
|
||||||
if (d->m_file.isEmpty()) { // document was created empty
|
if (d->m_file.isEmpty()) { // document was created empty
|
||||||
d->prepareSaving();
|
if (!d->prepareSaving()) {
|
||||||
|
Q_EMIT canceled(QString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (saveFile()) {
|
if (saveFile()) {
|
||||||
return saveToUrl();
|
return saveToUrl();
|
||||||
@@ -170,7 +173,14 @@ bool ReadWritePart::saveAs(const QUrl &url)
|
|||||||
d->m_originalURL = d->m_url;
|
d->m_originalURL = d->m_url;
|
||||||
d->m_originalFilePath = d->m_file;
|
d->m_originalFilePath = d->m_file;
|
||||||
d->m_url = url; // Store where to upload in saveToURL
|
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
|
bool result = save(); // Save local file and upload local file
|
||||||
if (result) {
|
if (result) {
|
||||||
if (d->m_originalURL != d->m_url) {
|
if (d->m_originalURL != d->m_url) {
|
||||||
@@ -190,7 +200,7 @@ bool ReadWritePart::saveAs(const QUrl &url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set m_file correctly for m_url
|
// Set m_file correctly for m_url
|
||||||
void ReadWritePartPrivate::prepareSaving()
|
bool ReadWritePartPrivate::prepareSaving()
|
||||||
{
|
{
|
||||||
// Local file
|
// Local file
|
||||||
if (m_url.isLocalFile()) {
|
if (m_url.isLocalFile()) {
|
||||||
@@ -200,17 +210,22 @@ void ReadWritePartPrivate::prepareSaving()
|
|||||||
m_bTemp = false;
|
m_bTemp = false;
|
||||||
}
|
}
|
||||||
m_file = m_url.toLocalFile();
|
m_file = m_url.toLocalFile();
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Remote file
|
// Remote file
|
||||||
// We haven't saved yet, or we did but locally - provide a temp file
|
// We haven't saved yet, or we did but locally - provide a temp file
|
||||||
if (m_file.isEmpty() || !m_bTemp) {
|
if (m_file.isEmpty() || !m_bTemp) {
|
||||||
QTemporaryFile tempFile;
|
QTemporaryFile tempFile;
|
||||||
tempFile.setAutoRemove(false);
|
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_file = tempFile.fileName();
|
||||||
m_bTemp = true;
|
m_bTemp = true;
|
||||||
}
|
}
|
||||||
// otherwise, we already had a temp file
|
// otherwise, we already had a temp file
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +259,11 @@ bool ReadWritePart::saveToUrl()
|
|||||||
d->m_uploadJob = nullptr;
|
d->m_uploadJob = nullptr;
|
||||||
}
|
}
|
||||||
QTemporaryFile *tempFile = new QTemporaryFile();
|
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();
|
QString uploadFile = tempFile->fileName();
|
||||||
delete tempFile;
|
delete tempFile;
|
||||||
QUrl uploadUrl = QUrl::fromLocalFile(uploadFile);
|
QUrl uploadUrl = QUrl::fromLocalFile(uploadFile);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
|
|
||||||
void slotUploadFinished(KJob *job);
|
void slotUploadFinished(KJob *job);
|
||||||
|
|
||||||
void prepareSaving();
|
bool prepareSaving();
|
||||||
|
|
||||||
bool m_bModified;
|
bool m_bModified;
|
||||||
bool m_bReadWrite;
|
bool m_bReadWrite;
|
||||||
|
|||||||
Reference in New Issue
Block a user