-
Notifications
You must be signed in to change notification settings - Fork 142
Add support for nested file paths when creating new files #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for nested file paths when creating new files #367
Conversation
…ikashkhati007/athas into vikashkhati007-feat/support-nested-file-paths
|
@coderabbitai Please review the changes |
|
@mehmetozguldev, I'll review the changes in this PR that adds support for nested file path creation. ✅ Actions performedReview triggered.
|
WalkthroughThe 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/file-system/controllers/store.ts
Outdated
| for (const folder of parts) { | ||
| currentPath = await get().createDirectory(currentPath, folder); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mehmetozguldev
left a comment
There was a problem hiding this 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!
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.
components/ui/Button.tsxScreenshots/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