From 9d807101e4a77ba625704d040f3f20137d346256 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Thu, 15 Oct 2026 06:20:56 +1300 Subject: [PATCH] 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 --- sources/qetproject.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index caf4816af..a3af26ee7 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -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