Keep a .qet project when its .qetz cannot be saved beside it

Saving a project opened from a .qet writes a .qetz beside it. In a
read-only folder that write fails, but the project had already been
switched to the .qetz path: the window then named a file that does not
exist, and the error said only "Permission denied".

The project now stays the .qet it was when the write fails, and the error
names the file: "Cannot save /path/name.qetz: Permission denied". Save as
still saves it elsewhere.

Found answering the review of #1472 (scorpio810, point 12).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-15 06:20:56 +13:00
parent f244f6dda0
commit 9d807101e4
+13 -3
View File
@@ -2721,10 +2721,20 @@ QETResult QETProject::write()
return(QString("unable to save project to file: no filepath was specified"));
//A project read from a .qet is saved as a .qetz beside it; the
//.qet stays as it was (stage D1)
//.qet stays as it was (stage D1). If the .qetz cannot be written
//(a read-only folder), the project stays the .qet it was.
const QString opened_qet = m_opened_from_qet ? m_file_path : QString();
if (m_opened_from_qet) {
setFilePath(besideContainerPath());
}
const auto failed = [this, &opened_qet](const QString &error) {
const QString message = tr("Cannot save %1: %2").arg(m_file_path, error);
if (!opened_qet.isEmpty()) {
setFilePath(opened_qet);
m_opened_from_qet = true;
}
return(QETResult(message));
};
// If the project was opened read-only, only refuse when the target
// really can't be written: an existing file that is not writable, or a
@@ -2746,7 +2756,7 @@ QETResult QETProject::write()
//A container is written from the whole document: every folio
//built (stage D4 writes it from the database)
if (!writeContainerFile(m_file_path, &error_message))
return(error_message);
return(failed(error_message));
}
else
{
@@ -2756,7 +2766,7 @@ QETResult QETProject::write()
QDomDocument xml_project(toXml(&kept_folios));
if (!QET::writeXmlText(spliceKeptFolios(xml_project.toString(4), kept_folios),
m_file_path, &error_message))
return(error_message);
return(failed(error_message));
}
// The project has just been written to a writable file (e.g. saved to