Skip to content

Fix mkdir dedupeName for existing directories#3215

Merged
Salazareo merged 1 commit into
HeyPuter:mainfrom
xsourabhsharma:fix-mkdir-dedupename-directory
Jun 7, 2026
Merged

Fix mkdir dedupeName for existing directories#3215
Salazareo merged 1 commit into
HeyPuter:mainfrom
xsourabhsharma:fix-mkdir-dedupename-directory

Conversation

@xsourabhsharma
Copy link
Copy Markdown
Contributor

@xsourabhsharma xsourabhsharma commented Jun 5, 2026

Summary

  • Fix mkdir so dedupeName creates a suffixed directory when the target directory already exists.
  • Preserve existing idempotent mkdir behavior when dedupeName is false.
  • Require parent write access when an existing target will be deduped into a sibling path.
  • Add modern and legacy controller regressions for hello -> hello (1) and the parent-write ACL guard.

Root cause

FSService.mkdir returned an existing directory before considering dedupeName, so duplicate directory creation never reached the dedupe path.

Review follow-up

Copilot flagged that deduping an existing directory creates a sibling path, so target-path authorization alone could be too weak for app-owned AppData roots. The controllers now require parent write access when dedupeName collides with an existing target before calling FSService.mkdir.

Tests

  • npm run test:backend -- src/backend/controllers/fs/FSController.test.ts src/backend/controllers/fs/LegacyFSController.test.ts
  • npm run build:ts

Closes #3201

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 5, 2026

CLA assistant check
All committers have signed the CLA.

@xsourabhsharma xsourabhsharma marked this pull request as ready for review June 5, 2026 03:20
@Salazareo Salazareo requested review from Salazareo and Copilot June 5, 2026 22:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes FSService.mkdir so dedupeName is honored when the target path already exists as a directory (creating a suffixed directory like hello (1)), while keeping the existing idempotent behavior when dedupeName is false. It also adds regression tests for both modern and legacy FS controllers to ensure the hellohello (1) behavior.

Changes:

  • Update FSService.mkdir to dedupe directory names when the target directory already exists and dedupeName is enabled.
  • Preserve idempotent mkdir behavior when dedupeName is disabled and the target directory already exists.
  • Add modern + legacy controller regression tests covering the dedupe behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/backend/services/fs/FSService.ts Adjusts mkdir conflict handling so existing directories trigger dedupe when requested.
src/backend/controllers/fs/LegacyFSController.test.ts Adds regression coverage for legacy mkdir dedupe behavior (hellohello (1)).
src/backend/controllers/fs/FSController.test.ts Adds regression coverage for modern mkdir dedupe behavior (hellohello (1)).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 2841 to +2848
if (existing) {
if (existing.isDir) {
// A directory already exists at path: idempotent success.
return existing;
}
if (input.overwrite) {
if (input.dedupeName) {
name = await this.#findDedupedName(parent, name);
} else {
// A directory already exists at path: idempotent success.
return existing;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see the check in the controller, copilot just dumb at bricks, lgtm

@xsourabhsharma xsourabhsharma force-pushed the fix-mkdir-dedupename-directory branch from 45d65bc to 9ee93fe Compare June 6, 2026 01:44
Copy link
Copy Markdown
Member

@Salazareo Salazareo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, but just gonna get copilot to scan in case I missed anything

@xsourabhsharma
Copy link
Copy Markdown
Contributor Author

@Salazareo Thanks for checking. I also verified this locally on the PR branch: the FSController/LegacyFSController mkdir suites pass, ClaudeProvider.test.ts passes, and npm run build:ts passes.

The red CI job looks unrelated to this mkdir change. The GitHub log shows the backend tests passed, then Vitest reported an unhandled teardown rejection from src/backend/drivers/ai-chat/providers/claude/ClaudeProvider.test.ts. I think rerunning the failed backend job is the right next step.

@Salazareo Salazareo merged commit 15134c9 into HeyPuter:main Jun 7, 2026
6 of 7 checks passed
@Salazareo
Copy link
Copy Markdown
Member

merged @xsourabhsharma thanks for the contribution!

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.

puter.fs.mkdir with dedupeName doesn't work

4 participants