Skip to content

test(desktop): pin autosave's recreate-missing-directory behavior (#3509) - #4657

Merged
Jocs merged 1 commit into
developfrom
fix/issue-3509-autosave-no-recreate-dir
Jun 23, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/issue-3509-autosave-no-recreate-dir

Conversation

@Jocs

@Jocs Jocs commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Re: #3509 — autosave "re-creates files and folders when they are moved away".

After review we decided this behavior is intentional and correct: when a file's parent folder has been moved or deleted while the file is open, saving (including autosave) recreates the directory tree and writes the file, rather than failing. This matches VS Code, which also recreates a deleted parent directory on save, and it ensures an (auto)save never silently fails or loses the user's edits.

This PR therefore makes no behavior change. It just:

  • Adds unit coverage pinning the intended behavior (writeFile recreates a missing parent directory and writes the file; and writes normally when the directory exists).
  • Adds a short comment on the outputFile call documenting why it's used, so the behavior isn't mistaken for the bug in autosave re-creates files and folders when they are moved away #3509 and "fixed" by switching to a plain write.

Test

pnpm -C packages/desktop exec vitest run test/unit/specs/write-file-missing-dir.spec.ts

Both cases pass; typecheck clean.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4657:

Run: https://github.com/marktext/marktext/actions/runs/28027928374

Artifact Size Link
marktext-windows-arm64 275.8 MB Download
marktext-linux 627.5 MB Download
marktext-windows-x64 283.9 MB Download
marktext-macos-x64 293.1 MB Download
marktext-macos-arm64 282.8 MB Download

@Jocs

Jocs commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

Closing without merging. After review we've decided to keep the current behavior: on save (including autosave), MarkText recreates the directory tree and writes the file, rather than failing when the parent folder was moved/deleted.

This is consistent with VS Code, which also recreates a deleted parent directory when you save an open file. The priority for (auto)save is to never silently lose the user's edits. See #3509 for the full rationale.

@Jocs Jocs closed this Jun 23, 2026
@Jocs
Jocs deleted the fix/issue-3509-autosave-no-recreate-dir branch June 23, 2026 10:49
@Jocs
Jocs restored the fix/issue-3509-autosave-no-recreate-dir branch June 23, 2026 10:51
@Jocs Jocs reopened this Jun 23, 2026
@Jocs
Jocs force-pushed the fix/issue-3509-autosave-no-recreate-dir branch from b72932a to 3ca9910 Compare June 23, 2026 10:55
@Jocs Jocs changed the title fix(desktop): don't recreate a moved-away directory on save/autosave (#3509) test(desktop): pin autosave's recreate-missing-directory behavior (#3509) Jun 23, 2026
)

When a file's folder is moved/deleted while it is open, saving recreates
the directory tree and writes the file (fs-extra `outputFile`), matching
VS Code so an (auto)save never silently fails. This is intentional but was
untested — add unit coverage and a comment documenting the rationale so it
isn't mistaken for a bug and "fixed" by switching to a plain write.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Jocs
Jocs force-pushed the fix/issue-3509-autosave-no-recreate-dir branch from 3ca9910 to a294193 Compare June 23, 2026 12:58
@Jocs
Jocs merged commit e0f2f3b into develop Jun 23, 2026
10 checks passed
@Jocs
Jocs deleted the fix/issue-3509-autosave-no-recreate-dir branch June 23, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant