Repository navigation
fix: prevent file recreation at deleted path on save #679
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: master
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 |
|---|---|---|
|
|
@@ -1103,7 +1103,13 @@ bool Window::closeTab(const QString &filePath) | |
| } | ||
| } else { | ||
| qDebug() << "File is not a backup file, saving normally"; | ||
| 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"; | ||
| removeWrapper(filePath, true); | ||
| m_tabbar->closeCurrentTab(filePath); | ||
|
|
@@ -1557,7 +1563,9 @@ QString Window::saveAsFileToDisk() | |
| dialog.selectFile(match.captured(0) + ".txt"); | ||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 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, For a missing source, choose a fallback directory and avoid preselecting the deleted file's original pathname. Also at Prompt for AI agentsIn `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`. |
||
| dialog.setDirectory(fileInfo.dir()); | ||
| } | ||
| dialog.selectFile(fileInfo.fileName()); | ||
| qDebug() << "Setting dialog file name to current file name:" << fileInfo.fileName(); | ||
| } | ||
|
|
@@ -1685,7 +1693,9 @@ QString Window::saveBlankFileToDisk() | |
| dialog.selectFile(match.captured(0) + ".txt"); | ||
| 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()); | ||
| } | ||
| dialog.selectFile(fileInfo.fileName()); | ||
| qDebug() << "Setting dialog file name to current file name:" << fileInfo.fileName(); | ||
| } | ||
|
|
@@ -1734,7 +1744,9 @@ bool Window::saveAsOtherTabFile(EditWrapper *wrapper) | |
| dialog.selectFile(match.captured(0) + ".txt"); | ||
| 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()); | ||
| } | ||
| dialog.selectFile(fileInfo.fileName()); | ||
| qDebug() << "Setting dialog file name to current file name:" << fileInfo.fileName(); | ||
| } | ||
|
|
||
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 · Saved tab stays open
When the source file is missing and Save As succeeds while closing the tab,
closeTab()proceeds past successfulsaveAsFile()without callingremoveWrapper()orm_tabbar->closeCurrentTab(), then returns true; callers such ascloseAllFiles()count the tab as closed even though it remains open.Run the normal successful-save cleanup after
saveAsFile()succeeds.Prompt for AI agents