fix(desktop): allow saving directly to a drive root (#5150) - #5188
Open
Panisnbb wants to merge 1 commit into
Open
fix(desktop): allow saving directly to a drive root (#5150)#5188Panisnbb wants to merge 1 commit into
Panisnbb wants to merge 1 commit into
Conversation
writeFile() unconditionally ensured the target's parent directory existed. On Windows, fs.mkdir() returns EPERM (not EEXIST) for an existing volume root (e.g. "E:\\"), so saving directly to a drive root failed with "operation not permitted".
Panisnbb
force-pushed
the
fix/desktop-save-drive-root
branch
from
August 26, 2026 02:11
92f2960 to
5885fcf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5150
Problem
Saving a markdown file directly to a disk drive root (e.g.
E:\orD:\) on Windows fails and blocks the save entirely, as reported in #5150.Root cause
writeFile()inpackages/desktop/src/main/filesystem/index.tsunconditionally calledensureDir()on the target's parent directory before writing. fs-extra'sensureDir()maps tofs.mkdir(dir, { recursive: true }). On Windows,fs.mkdir()throwsEPERM(not the usualEEXIST) when the path is an existing volume root such asE:\. Node handles a filesystem-root path specially, so an existing parent — a drive root included — failed the save with:This is independent of the drive's ACL / write permission: even a writable drive root fails, because the error occurs at the
mkdirstep before any file write is attempted. That is why it reproduced on every drive root on Windows.Fix
Only call
ensureDir()when the parent directory does not already exist:isDirectory()returnsfalsefor a missing parent andensureDir()still runs.isDirectory()useslstatSync(does not follow symlinks), so symlinked parents still fall through toensureDir(), keeping prior behaviour unchanged.Cross-platform safety
The change is platform-neutral and only uses
lstatSync. On macOS/Linux an existing parent directory is likewise a no-op (recursivemkdiron an existing directory succeeds silently), so the only behavioural change is skipping a redundant — and on Windows, failing — call on a drive root. Symlink and deleted-parent handling are unchanged.Verification
EPERM: operation not permitted, mkdir 'E:\'.E:\directly, to an existing directory, to a recreated (deleted) parent, and to a normal new file.pnpm typecheckpasses; the changed file is lint-clean.write-file-missing-dir.spec.ts(autosave re-creates files and folders when they are moved away #3509, 2 tests) still passes, confirming the recreate-missing-parent behaviour is unchanged.