Repository navigation
fix: fix file monitoring lost after recreate save #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/1071
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,12 +45,13 @@ | |
| #include <QDebug> | ||
| #include <QThreadPool> | ||
| #include <QtConcurrent/QtConcurrent> | ||
| #include <QScreen> | ||
| #include <QFormLayout> | ||
| #include <QShortcut> | ||
| #include <QTimer> | ||
| #include <QJsonObject> | ||
| #ifdef DTKCORE_CLASS_DConfigFile | ||
| #include <DConfig> | ||
| DCORE_USE_NAMESPACE | ||
| #endif | ||
|
|
||
|
|
@@ -2949,10 +2950,17 @@ | |
| SimpleQueryDialog dialog(this); | ||
| int iResult = dialog.showDialog(strDesText, tr("Cancel", "button"), DDialog::ButtonNormal, tr("Update", "button"), DDialog::ButtonRecommend); | ||
| if (1 == iResult) { | ||
| // 对重命名或删除导致的文件不存在的情况,不给出任何提示,且从文件监控中去掉此文件 | ||
| // 文件不存在可能是编辑器"先删除再创建"的保存方式,延迟重检而非直接移除监控 | ||
| if (!QFile::exists(strPath)) { | ||
| mapStatus.remove(strPath); | ||
| mapPassword.remove(strPath); | ||
| mapStatus[strPath] = false; | ||
| QTimer::singleShot(2000, this, [this, strPath]() { | ||
| if (QFile::exists(strPath)) { | ||
|
Comment on lines
+2956
to
+2957
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Stale files update wrong archive When the archive is reset or switched before the two-second callback runs and the old extracted file still exists, the queued Cancel the pending callback or check that the same archive is still active before re-adding the watch. Prompt for AI agentsIn `src/source/mainwindow.cpp` at lines 2956-2957:
**Stale files update wrong archive**
When the archive is reset or switched before the two-second callback runs and the old extracted file still exists, the queued `QTimer::singleShot` callback calls `addWatchFile(strPath)` after `resetMainwindow()` clears the watcher state, so later changes are handled against the current archive and can prompt or apply the stale file to the wrong archive.
Cancel the pending callback or check that the same archive is still active before re-adding the watch. |
||
| m_pOpenFileWatcher->addWatchFile(strPath); | ||
|
Comment on lines
+2956
to
+2958
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Confirmed updates are not saved When the user chooses Update while the file is temporarily absent, the missing-file branch returns before Defer the requested archive update until the missing file is available again. Prompt for AI agentsIn `src/source/mainwindow.cpp` at lines 2956-2958:
**Confirmed updates are not saved**
When the user chooses Update while the file is temporarily absent, the missing-file branch returns before `addFiles2Archive`; the timer only restores monitoring, so the confirmed update is not written to the archive unless another edit triggers a new prompt.
Defer the requested archive update until the missing file is available again.
Comment on lines
+2956
to
+2958
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Edits during the gap go unnoticed When the file is recreated and edited again before the delayed recheck, Detect changes that occur during the unwatched interval when restoring the watch. Prompt for AI agentsIn `src/source/mainwindow.cpp` at lines 2956-2958:
**Edits during the gap go unnoticed**
When the file is recreated and edited again before the delayed recheck, `QFileSystemWatcher` has no watch during the delay, and the callback only re-adds it; the intervening change is not replayed, so the user receives no prompt for that edit.
Detect changes that occur during the unwatched interval when restoring the watch.
Comment on lines
+2957
to
+2958
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Recreation race loses watch When the external editor deletes or replaces the file between the existence check and Check whether Also at Prompt for AI agentsIn `src/source/mainwindow.cpp` at lines 2957-2958:
**Recreation race loses watch**
When the external editor deletes or replaces the file between the existence check and `addPath()`, the file can disappear after `QFile::exists()` succeeds but before `addWatchFile()` calls `addPath()`. `addPath()` then fails while the status remains false, leaving no watch to detect a later recreation.
Check whether `addPath()` succeeded and retry or monitor the parent directory when it fails.
Also at `src/source/common/openFileWatcher.cpp:44`. |
||
| } else { | ||
|
Comment on lines
+2956
to
+2959
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Later edits stop prompting When the editor recreates the file more than two seconds after the delayed check, the callback removes Keep monitoring the missing path with a directory watch or retry until the file is recreated. Also at Prompt for AI agentsIn `src/source/mainwindow.cpp` at lines 2956-2959:
**Later edits stop prompting**
When the editor recreates the file more than two seconds after the delayed check, the callback removes `strPath` from the status map at its sole check; when the file appears later, no watch or retry detects it, so subsequent edits stop prompting the user.
Keep monitoring the missing path with a directory watch or retry until the file is recreated.
Also at `src/source/mainwindow.cpp:2961`. |
||
| QMap<QString, bool> &status = m_pOpenFileWatcher->getFileHasModified(); | ||
| status.remove(strPath); | ||
| } | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High · Cancel leaves the file unwatched
When the user cancels while a delete-and-recreate save has temporarily removed the file,
slotOpenFileChangedschedules the delayed recheck only in the Update branch; after Cancel,addWatchFileruns while the path is missing and no retry restores monitoring, so later edits do not prompt the user.Schedule the delayed recheck for a missing file regardless of whether the user chooses Update or Cancel.
Also at
src/source/mainwindow.cpp:2956-2964.Prompt for AI agents