fix(filesystem): allow create_directory to create nested parent directories - #4697
Open
AbhiPra24 wants to merge 1 commit into
Open
Conversation
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.
Description
Fixes #4629.
The tool description and documentation for
create_directoryexplicitly state that it can create multiple nested directories in one operation ("Creates parent directories if needed", "Can create multiple nested directories in one operation"). However,validatePath()rejected paths when their immediate parent did not yet exist with"Parent directory does not exist: <path>".This PR adds an
allowMissingParentsparameter tovalidatePath()(defaulting tofalsefor other file operations to maintain strict behavior). When enabled forcreate_directory,validatePath()securely verifies all ancestors up to the closest existing directory against the allowed directories list, ensuring path security is maintained while allowingfs.mkdir(validPath, { recursive: true })to create intermediate directories as documented.Changes
validatePathinsrc/filesystem/lib.tsto acceptallowMissingParents: boolean = falseand securely walk up to the nearest existing ancestor.create_directoryinsrc/filesystem/index.tsto passallowMissingParents = true.src/filesystem/__tests__/lib.test.tsverifyingallowMissingParents: truesucceeds for nested non-existent directory hierarchies within allowed roots.Verification
npm testandnpm run buildinsrc/filesystem. All 153 tests pass.