Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/source/common/openFileWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void OpenFileWatcher::addWatchFile(const QString &strFile)
m_pOpenFileWatcher->addPath(strFile);

// 第一次默认文件未修改
if (m_mapFileHasModified.find(strFile) != m_mapFileHasModified.end()) {
m_mapFileHasModified[m_strOpenFile] = false;
if (m_mapFileHasModified.find(strFile) == m_mapFileHasModified.end()) {
m_mapFileHasModified[strFile] = false;
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/source/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@
#include <QDebug>
#include <QThreadPool>
#include <QtConcurrent/QtConcurrent>
#include <QScreen>

Check warning on line 48 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QScreen> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFormLayout>

Check warning on line 49 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFormLayout> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QShortcut>

Check warning on line 50 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QShortcut> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 51 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonObject>

Check warning on line 52 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#ifdef DTKCORE_CLASS_DConfigFile
#include <DConfig>

Check warning on line 54 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DConfig> not found. Please note: Cppcheck does not need standard library headers to get proper results.
DCORE_USE_NAMESPACE
#endif

Expand Down Expand Up @@ -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)) {

Copy link
Copy Markdown

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, slotOpenFileChanged schedules the delayed recheck only in the Update branch; after Cancel, addWatchFile runs 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
In `src/source/mainwindow.cpp` at line 2954:

**Cancel leaves the file unwatched**

When the user cancels while a delete-and-recreate save has temporarily removed the file, `slotOpenFileChanged` schedules the delayed recheck only in the Update branch; after Cancel, `addWatchFile` runs 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`.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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, 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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;
}

Expand Down
Loading