Skip to content

Conversation

@vikashkhati007
Copy link
Contributor

@vikashkhati007 vikashkhati007 commented Oct 28, 2025

Pull Request

Enhanced the handleCreateNewFileInDirectory function to support nested file path creation.
This improvement allows users to directly create files inside multiple subdirectories (e.g. components/ui/Button.tsx), while automatically creating any intermediate folders that do not exist.

Description

Added support for nested file paths when creating new files.

  • Allows creating files like components/ui/Button.tsx
  • Automatically creates intermediate folders if they don't exist

Screenshots/Videos

Not applicable — this is a logic-level enhancement.

Related Issues

N/A – This PR introduces a new feature (nested file path creation support).

Summary by CodeRabbit

  • New Features
    • File creation accepts nested paths (e.g., "folder/subfolder/file.txt") and automatically creates intermediate directories.
  • Bug Fixes
    • Input validation prevents path traversal and illegal characters; added error handling with user-facing alerts for creation failures.

@mehmetozguldev mehmetozguldev self-requested a review October 28, 2025 12:27
@mehmetozguldev
Copy link
Contributor

@coderabbitai Please review the changes

@athasdev athasdev deleted a comment from coderabbitai bot Oct 31, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 31, 2025

@mehmetozguldev, I'll review the changes in this PR that adds support for nested file path creation.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Oct 31, 2025

Walkthrough

The store controller's file-creation handler now accepts nested file paths: it splits the provided path on "/", rejects path-traversal/invalid segments, creates intermediate directories as needed, then creates the file in the deepest directory with added try/catch error handling and user alerts.

Changes

Cohort / File(s) Summary
Nested path file creation
src/file-system/controllers/store.ts
Reworked handleCreateNewFileInDirectory to split fileName by "/", validate segments (reject .., empty or illegal segments), sequentially create intermediate directories, create the final file in the deepest directory, and surface errors/alerts on failure. No public API signature changes.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Handler as "handleCreateNewFileInDirectory"
    participant DirCreator as "Directory Creation"
    participant FileCreator as "File Creation"
    participant Alert as "User Alert / Error"

    Caller->>Handler: request create "a/b/c/file.txt"
    Handler->>Handler: split path, validate segments (no .., no empty)
    alt invalid path
        Handler->>Alert: emit invalid-path alert
        Alert-->>Caller: error
    else valid path
        Handler->>DirCreator: ensure intermediate directories exist
        loop per segment
            DirCreator->>DirCreator: create/ensure dir (async)
        end
        DirCreator-->>Handler: directories ready
        Handler->>FileCreator: create file in deepest dir
        alt create success
            FileCreator-->>Caller: success
        else create failure
            FileCreator->>Alert: emit creation-failure alert
            Alert-->>Caller: error
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review path validation (trailing slashes, empty segments, absolute vs relative, .. handling).
  • Verify async sequencing for directory creation to avoid race conditions and ensure proper error propagation.
  • Check error logging and user alert messages for clarity and consistency.

Poem

🐇 I dig a tunnel, step by step,
Making rooms where pathways crept,
Each folder sprouts beneath my paws,
Till final file obeys the laws,
Hooray — deep nests for code at rest! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for nested file paths when creating new files. This directly matches the primary enhancement in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7f0579 and 996d881.

📒 Files selected for processing (1)
  • src/file-system/controllers/store.ts (1 hunks)

Comment on lines 394 to 396
for (const folder of parts) {
currentPath = await get().createDirectory(currentPath, folder);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add error handling for directory creation to prevent inconsistent state.

If directory creation fails at any intermediate step (e.g., permissions error, disk full, invalid name), the function will throw and leave the file system with partially created directories but no final file. This creates an inconsistent state without clear feedback to the user.

Apply this diff to add proper error handling:

-// Create intermediate folders if they don't exist
-for (const folder of parts) {
-  currentPath = await get().createDirectory(currentPath, folder);
-}
-
-// Finally create the file inside the deepest folder
-return get().createFile(currentPath, finalFileName);
+// Create intermediate folders if they don't exist
+try {
+  for (const folder of parts) {
+    currentPath = await get().createDirectory(currentPath, folder);
+  }
+
+  // Finally create the file inside the deepest folder
+  return await get().createFile(currentPath, finalFileName);
+} catch (error) {
+  console.error("Failed to create nested file:", error);
+  alert(`Failed to create file: ${error instanceof Error ? error.message : "Unknown error"}`);
+  return;
+}

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/file-system/controllers/store.ts around lines 394 to 396, the loop that
calls createDirectory for each path part lacks error handling and can leave
partially created directories on failure; update this block to wrap each
createDirectory call in a try/catch, track the list of successfully created
directories (or the first created base path), and if any createDirectory throws,
perform cleanup by removing those created directories (or reverting to the
previous state), log or attach the original error details, and then rethrow or
return a clear error to the caller so the caller knows creation failed and the
filesystem is not left in an inconsistent state.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 996d881 and 03a26a9.

📒 Files selected for processing (1)
  • src/file-system/controllers/store.ts (1 hunks)

Copy link
Contributor

@mehmetozguldev mehmetozguldev left a comment

Choose a reason for hiding this comment

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

This is working perfectly. Thank you!

@mehmetozguldev mehmetozguldev changed the title Feat: Support nested file paths when creating new files Add support for nested file paths when creating new files Nov 8, 2025
@mehmetozguldev mehmetozguldev merged commit b047ca3 into athasdev:master Nov 8, 2025
2 checks passed
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.

2 participants