Repository navigation
Conversation
1. Root cause: closeTab() called saveFile() without checking whether the source file still existed on disk; deleted files were silently recreated at their original path, conflicting with trash metadata and showing "locked" in file manager 2. Fix: closeTab() now checks fileInfo.exists() before saving; if the file is gone, it redirects to saveAsFile() instead; saveAsFileToDisk(), saveBlankFileToDisk(), and saveAsOtherTabFile() only set the dialog directory when the original file still exists, avoiding pointing to a deleted directory 3. Impact: closing a tab whose source file was moved to trash now prompts Save As instead of recreating the file; existing save paths for present files are unchanged Log: Fixed issue where saving after deleting the source file recreated it at the original path, causing trash lock conflict Influence: 1. Open a txt file, edit it, delete the source file, close the editor and choose Save — verify Save As dialog appears 2. Open a txt file, edit it, close the editor and choose Save with the file still present — verify normal save works 3. Test saveAs, saveBlank, and saveAsOtherTab when source file is deleted — verify dialog does not default to deleted path fix: 修复删除源文件后保存导致原路径重建文件的问题 1. 根因:closeTab() 在保存前未检查源文件是否仍存在于磁盘, 直接调用 saveFile() 在原路径重建文件,与回收站元数据冲突, 导致文件管理器回收站显示"锁定"状态 2. 方案:closeTab() 保存前检查 fileInfo.exists(),文件不存在时 改用 saveAsFile() 引导用户另存;saveAsFileToDisk()、 saveBlankFileToDisk()、saveAsOtherTabFile() 仅在原始文件 仍存在时设置对话框目录,避免指向已删除的目录 3. 影响:关闭源文件已移入回收站的标签页时,将弹出另存对话框 而非在原路径重建文件;文件存在时的保存行为不变 Log: 修复删除源文件后保存时在原路径重建文件导致回收站锁定的问题 Influence: 1. 打开 txt 文件编辑后删除源文件,关闭编辑器选择保存, 验证弹出另存对话框 2. 打开 txt 文件编辑后正常关闭保存,验证保存功能正常 3. 测试源文件被删除时的另存为、空白保存、其他标签页保存, 验证对话框不默认指向已删除目录 PMS: BUG-366573
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates save and tab-closing flows to detect deleted source files, prompt for an alternate destination instead of recreating them, and avoid defaulting save dialogs to deleted directories while preserving existing-file behavior. Sequence diagram for saving a tab after its source file is deletedsequenceDiagram
participant User
participant Window
participant QFileInfo
participant SaveDialog
participant EditWrapper
User->>Window: closeTab(filePath)
Window->>QFileInfo: exists()
alt source file is missing
Window->>Window: saveAsFile()
Window->>SaveDialog: saveAsFileToDisk()
SaveDialog-->>Window: alternate destination
Window->>EditWrapper: saveFile(destination)
Window-->>User: close tab after Save As
else source file still exists
Window->>EditWrapper: saveFile()
EditWrapper-->>Window: save result
Window-->>User: close tab after normal save
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/widgets/window.cpp" line_range="1566" />
<code_context>
qDebug() << "Setting dialog file name to draft file name:" << match.captured(0) + ".txt";
} else {
- dialog.setDirectory(fileInfo.dir());
+ if (fileInfo.exists()) {
+ dialog.setDirectory(fileInfo.dir());
+ }
</code_context>
<issue_to_address>
**Save As recreates deleted file**
When the source is deleted, its parent directory still exists, and the configured save location resolves to that parent, `saveAsFileToDisk()` leaves the dialog in the source's parent directory and `dialog.selectFile(fileInfo.fileName())` preselects the original pathname; accepting the default saves back to that path and recreates the deleted file.
For a missing source, choose a fallback directory and avoid preselecting the deleted file's original pathname.
Also at `src/widgets/window.cpp:1567-1570`.
</issue_to_address>
### Comment 2
<location path="src/widgets/window.cpp" line_range="1108-1111" />
<code_context>
- if (wrapper->saveFile()) {
+ if (!fileInfo.exists()) {
+ qDebug() << "File no longer exists on disk, redirecting to Save As";
+ if (!saveAsFile()) {
+ qWarning() << "Save as file cancelled or failed, keep tab open";
+ return false;
+ }
+ } else if (wrapper->saveFile()) {
qDebug() << "File saved, removing wrapper and closing tab";
</code_context>
<issue_to_address>
**Saved tab stays open**
When the source file is missing and Save As succeeds while closing the tab, `closeTab()` proceeds past successful `saveAsFile()` without calling `removeWrapper()` or `m_tabbar->closeCurrentTab()`, then returns true; callers such as `closeAllFiles()` count the tab as closed even though it remains open.
Run the normal successful-save cleanup after `saveAsFile()` succeeds.
</issue_to_address>| qDebug() << "Setting dialog file name to draft file name:" << match.captured(0) + ".txt"; | ||
| } else { | ||
| dialog.setDirectory(fileInfo.dir()); | ||
| if (fileInfo.exists()) { |
There was a problem hiding this comment.
🟠 High · Save As recreates deleted file
When the source is deleted, its parent directory still exists, and the configured save location resolves to that parent, saveAsFileToDisk() leaves the dialog in the source's parent directory and dialog.selectFile(fileInfo.fileName()) preselects the original pathname; accepting the default saves back to that path and recreates the deleted file.
For a missing source, choose a fallback directory and avoid preselecting the deleted file's original pathname.
Also at src/widgets/window.cpp:1567-1570.
Prompt for AI agents
In `src/widgets/window.cpp` at line 1566:
**Save As recreates deleted file**
When the source is deleted, its parent directory still exists, and the configured save location resolves to that parent, `saveAsFileToDisk()` leaves the dialog in the source's parent directory and `dialog.selectFile(fileInfo.fileName())` preselects the original pathname; accepting the default saves back to that path and recreates the deleted file.
For a missing source, choose a fallback directory and avoid preselecting the deleted file's original pathname.
Also at `src/widgets/window.cpp:1567-1570`.| if (!saveAsFile()) { | ||
| qWarning() << "Save as file cancelled or failed, keep tab open"; | ||
| return false; | ||
| } |
There was a problem hiding this comment.
🟠 High · Saved tab stays open
When the source file is missing and Save As succeeds while closing the tab, closeTab() proceeds past successful saveAsFile() without calling removeWrapper() or m_tabbar->closeCurrentTab(), then returns true; callers such as closeAllFiles() count the tab as closed even though it remains open.
Run the normal successful-save cleanup after saveAsFile() succeeds.
Prompt for AI agents
In `src/widgets/window.cpp` at lines 1108-1111:
**Saved tab stays open**
When the source file is missing and Save As succeeds while closing the tab, `closeTab()` proceeds past successful `saveAsFile()` without calling `removeWrapper()` or `m_tabbar->closeCurrentTab()`, then returns true; callers such as `closeAllFiles()` count the tab as closed even though it remains open.
Run the normal successful-save cleanup after `saveAsFile()` succeeds.
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['三处保存对话框函数(saveAsFileToDisk、saveBlankFileToDisk、saveAsOtherTabFile)中 fileInfo.exists() 守卫模式相同,若未来需扩展可考虑提取为公共辅助函数,但目前重复程度极低,无需立即重构。'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例当前代码已正确修复了问题,无需额外修改。完整修复逻辑如下: // closeTab 函数中的修复(src/widgets/window.cpp 约第1103行) if (!fileInfo.exists()) {
qDebug() << "File no longer exists on disk, redirecting to Save As";
if (!saveAsFile()) {
qWarning() << "Save as file cancelled or failed, keep tab open";
return false;
}
} else if (wrapper->saveFile()) {
qDebug() << "File saved, removing wrapper and closing tab";
removeWrapper(filePath, true);
m_tabbar->closeCurrentTab(filePath);
} // 保存对话框函数中的修复(三处相同模式) if (fileInfo.exists()) {
dialog.setDirectory(fileInfo.dir());
}本报告由 AI 代码审查工具自动生成 |
fix: prevent file recreation at deleted path on save
whether the source file still existed on disk; deleted files
were silently recreated at their original path, conflicting
with trash metadata and showing "locked" in file manager
if the file is gone, it redirects to saveAsFile() instead;
saveAsFileToDisk(), saveBlankFileToDisk(), and
saveAsOtherTabFile() only set the dialog directory when the
original file still exists, avoiding pointing to a deleted
directory
now prompts Save As instead of recreating the file; existing
save paths for present files are unchanged
Log: Fixed issue where saving after deleting the source file recreated it at the original path, causing trash lock conflict
Influence:
editor and choose Save — verify Save As dialog appears
with the file still present — verify normal save works
is deleted — verify dialog does not default to deleted path
fix: 修复删除源文件后保存导致原路径重建文件的问题
直接调用 saveFile() 在原路径重建文件,与回收站元数据冲突,
导致文件管理器回收站显示"锁定"状态
改用 saveAsFile() 引导用户另存;saveAsFileToDisk()、
saveBlankFileToDisk()、saveAsOtherTabFile() 仅在原始文件
仍存在时设置对话框目录,避免指向已删除的目录
而非在原路径重建文件;文件存在时的保存行为不变
Log: 修复删除源文件后保存时在原路径重建文件导致回收站锁定的问题
Influence:
验证弹出另存对话框
验证对话框不默认指向已删除目录
PMS: BUG-366573
Summary by Sourcery
Prevent deleted source files from being recreated during tab closure by requiring users to choose a new save location.
Bug Fixes: