Skip to content

Fix #459: failed to make New File and New Folder and show Error messa... - #469

Merged
purocean merged 1 commit into
purocean:developfrom
JiwaniZakir:fix/459-failed-to-make-new-file-and-new-folder-a
Apr 16, 2026
Merged

purocean merged 1 commit into
purocean:developfrom
JiwaniZakir:fix/459-failed-to-make-new-file-and-new-folder-a

Conversation

@JiwaniZakir

Copy link
Copy Markdown
Contributor

Closes #459

Motivation

On Windows, path.join() called inside withRepo strips the trailing slash from directory paths before the trailing-separator check runs. This caused both "New File" and "New Folder" operations to fall through to the file-write branch, producing ENOENT: no such file or directory (for files) or silently doing nothing (for folders) because the target directory path was treated as a file path.

Changes

src/main/server/file.ts — write function (~line 229)

The condition guarding fs.ensureDir previously only checked filePath.endsWith(path.sep), where filePath is derived from path.join() and therefore never has a trailing separator. The fix adds a check on the original p parameter (before withRepo normalizes it) for a trailing /:

- if (filePath.endsWith(path.sep)) {
+ if (p.endsWith('/') || filePath.endsWith(path.sep)) {

The p.endsWith('/') check preserves the intent of the caller's signal (a trailing slash means "this is a directory") regardless of how path.join normalizes the path on any OS.

Testing

  • Windows 11: Create a new file and a new folder via the UI — both complete without error and appear in the file tree.
  • macOS/Linux: Existing behavior is unchanged; p.endsWith('/') fires for directory paths on these platforms as well, making the fix consistent cross-platform.
  • Verified that writing a normal file (path with no trailing slash) is unaffected — the condition remains false and execution continues to the file-write logic.

This PR was created with AI assistance (Claude). The changes were reviewed by quality gates and a critic model before submission.

@vercel

vercel Bot commented Apr 16, 2026

Copy link
Copy Markdown

@JiwaniZakir is attempting to deploy a commit to the purocean's projects Team on Vercel.

A member of the Team first needs to authorize it.

@purocean
purocean merged commit 8e04d6c into purocean:develop Apr 16, 2026
1 check passed
@JiwaniZakir

Copy link
Copy Markdown
Contributor Author

The fix looks correct — checking the original p parameter before path.join() normalizes it is the right approach since path.join() intentionally strips trailing separators per Node.js spec. One thing worth verifying: on Windows, callers could potentially pass a trailing backslash (\) instead of /, so it might be worth adding p.endsWith('\\') to that condition or normalizing p's trailing separator before the check to cover that edge case. Also worth adding a test case specifically for the Windows path.sep stripping behavior to prevent regression.

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.

failed to make New File and New Folder and show Error message "ENOENT, no such file or directory"

2 participants