Fix #1579: no false "changed on disk" warning on a network share

On a CIFS/SMB share every save asked "Someone else changed the file on
disk", because the size and modification time read straight after
saving can be the client's cached values, not the server's final ones,
and the next save demanded an exact match.

The size and time are still the quick check. When they differ, the file
now counts as changed only if its content differs from what this QET
last read or wrote (a SHA-1 kept at open and after each save). A real
change by someone else still asks; the same bytes with a new time do
not.

tst_changedondisk: sameContentNewTimeSaves fails before and passes
after; the two conflict cases now move a symbol so the content really
changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-22 21:36:24 +13:00
parent 149d92545d
commit 3da3a78850
3 changed files with 50 additions and 7 deletions
+16 -1
View File
@@ -12,7 +12,9 @@
// when the file on disk is no longer that one. Driven through the real
// binary's --run: qet.save(<the project's own path>) writes the file behind
// the open project without updating what it remembers, which is exactly "someone
// else saved"; qet.save('') is the project's own save.
// else saved"; qet.save('') is the project's own save. Only a different content
// counts: the same bytes with a new time are what a network share reports
// right after our own save (#1579).
class tst_changedondisk : public QObject
{
Q_OBJECT
@@ -71,9 +73,21 @@ private slots:
QVERIFY2(out.contains(QStringLiteral("R2 true")), qPrintable(out));
}
void sameContentNewTimeSaves()
{
// the same bytes written behind the project (an unchanged project
// saves to an identical file, F124): only the time differs
const QString script = QStringLiteral(
"qet.save(%1);\nqet.log('R ' + qet.save(''));\n")
.arg(QStringLiteral("'") + m_project + QStringLiteral("'"));
const QString out = run(script, m_project);
QVERIFY2(out.contains(QStringLiteral("R true")), qPrintable(out));
}
void changedFileIsNotOverwritten()
{
const QString script = QStringLiteral(
"qet.moveElement(0, qet.elementUuids(0)[0], 10, 0);\n"
"qet.save(%1);\nqet.log('R ' + qet.save(''));\n")
.arg(QStringLiteral("'") + m_project + QStringLiteral("'"));
const QString out = run(script, m_project);
@@ -84,6 +98,7 @@ private slots:
void overrideOverwrites()
{
const QString script = QStringLiteral(
"qet.moveElement(0, qet.elementUuids(0)[0], 10, 0);\n"
"qet.save(%1);\nqet.log('R ' + qet.save(''));\n")
.arg(QStringLiteral("'") + m_project + QStringLiteral("'"));
const QString out = run(script, m_project, true);