mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-17 19:34:13 +02:00
Sync the folder after saving, and save from the command line through a temporary file
QSaveFile writes a new file, forces it to disk and renames it over the old one, but does not force the folder to disk. On ext4 or XFS a power cut soon after a save can then lose the rename: the previous file comes back, or none. QET::syncFolderOf() now syncs the folder after every project, symbol and title block save (QET::writeXmlText()) and every .qetz save (QetZip::write()). Nothing to do on Windows. --resave and --set-titleblock wrote a .qet straight over the output file (QFile, truncate, write): a run stopped part-way left half a project. They now write through QET::writeXmlText() like the GUI's save. On Windows their .qet now has LF line ends, as the GUI writes. Checked with strace on --resave: fdatasync of the new file, linkat into place, fsync of the folder. The .qet written is byte-identical to before. ctest 106/106. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+8
-12
@@ -885,14 +885,13 @@ int resaveProject(QETProject &project, const QString &output)
|
||||
//what building them would write (QETProject::toXml())
|
||||
QHash<int, QByteArray> kept_folios;
|
||||
const QDomDocument doc = project.toXml(&kept_folios);
|
||||
QFile file(output);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
err << "Cannot open '" << output << "' for writing.\n";
|
||||
//Through a temporary file, as the GUI saves: a run stopped
|
||||
//part-way leaves the previous file
|
||||
QString error;
|
||||
if (!QET::writeXmlText(QETProject::spliceKeptFolios(doc.toString(4), kept_folios), output, &error)) {
|
||||
err << "Cannot write '" << output << "': " << error << "\n";
|
||||
return 1;
|
||||
}
|
||||
QTextStream fout(&file);
|
||||
fout << QETProject::spliceKeptFolios(doc.toString(4), kept_folios);
|
||||
file.close();
|
||||
out << "Re-saved project -> " << output << "\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -980,14 +979,11 @@ int setTitleBlock(QETProject &project, const QString &output,
|
||||
//is what building them would write (QETProject::toXml())
|
||||
QHash<int, QByteArray> kept_folios;
|
||||
const QDomDocument doc = project.toXml(&kept_folios);
|
||||
QFile file(output);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
err << "Cannot open '" << output << "' for writing.\n";
|
||||
QString error;
|
||||
if (!QET::writeXmlText(QETProject::spliceKeptFolios(doc.toString(4), kept_folios), output, &error)) {
|
||||
err << "Cannot write '" << output << "': " << error << "\n";
|
||||
return 1;
|
||||
}
|
||||
QTextStream fout(&file);
|
||||
fout << QETProject::spliceKeptFolios(doc.toString(4), kept_folios);
|
||||
file.close();
|
||||
}
|
||||
out << "Stamped " << fields.size() << " field(s) on "
|
||||
<< folios << " folio(s) -> " << output << "\n";
|
||||
|
||||
Reference in New Issue
Block a user