refactor(file-browser): extract reusable deletion logic and abstract Termux URI validation - #2548
Open
AuDevTist1C wants to merge 1 commit into
Open
Conversation
… Termux URL checking Consolidate redundant file and directory deletion routines into a single reusable helper function to improve maintainability and reduce code duplication in fileBrowser. * **Deletion Logic Consolidation:** * Refactored duplicated recursive deletion routines across batch selection and individual item removal into a unified `deleteDirOrFile()` helper function. * Standardized post-deletion state cleanup including cache invalidation, recents removal, and active editor URI updates. * **Termux Traversal & Validation:** * Extracted Termux URI checking into a dedicated `isTermuxUrl()` helper function for cleaner reuse in rename and deletion handlers. * Streamlined recursive directory tree traversal for Termux storage backends by passing `fsOperation` instances directly. (AI generated commit message)
Contributor
Greptile SummaryRefactors file-browser deletion behavior without changing its external contract.
Confidence Score: 5/5The PR appears safe to merge, with the refactor preserving the existing deletion paths and cleanup behavior. Termux recursion still operates bottom-up on filesystem objects bound to each child URL, while both single-item and batch deletion retain their previous type resolution, filesystem deletion, editor cleanup, recents cleanup, open-folder cleanup, and cache invalidation. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Delete request] --> B{Type supplied?}
B -->|Yes| C[Classify with helpers.isDir]
B -->|No| D[Read fs.stat]
C --> E{Termux directory?}
D --> E
E -->|Yes| F[Recursively delete children]
F --> G[Delete directory]
E -->|No| H[Delete filesystem item]
G --> I[Clean editor, recents, folder, and cache state]
H --> I
Reviews (1): Last reviewed commit: "refactor(file-browser): extract reusable..." | Re-trigger Greptile |
2 tasks
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.
This pull request refactors the file and folder deletion routines within
src/pages/fileBrowser/fileBrowser.js. Previously, identical recursive deletion logic and post-deletion state cleanup were duplicated across both batch deletion (selection mode) and individual item removal (removeFile).By consolidating these workflows into targeted helper functions (
deleteDirOrFileandisTermuxUrl), this PR reduces code redundancy by ~26 lines, improves readability, and ensures consistent state maintenance across all deletion paths.🛠️ Key Changes
1. Unified Deletion Logic (
deleteDirOrFile)async function deleteDirOrFile(url, type)helper that handles both single files and directories.deleteDirOrFile:helpers.updateUriOfAllActiveFiles).recents.removeFolder/recents.removeFile).openFolder.removeItem).delete cachedDir[url]).for (const url of selectedItems) await deleteDirOrFile(url);) and single-file deletion (removeFile).2. Termux URI Validation Abstraction (
isTermuxUrl)isTermuxUrl(url)to encapsulate string checking for thecontent://com.termux.documents/tree/provider.${url ?? ""}) to prevent runtime null/undefined evaluation errors.url.startsWith(...)calls in rename handlers and recursive deletion steps withisTermuxUrl().3. Streamlined Recursive Termux Directory Traversal
deleteRecursivelyto passfsOperationinstances directly down the call chain instead of repeatedly constructing new instances from raw string URIs at each recursive step.🔬 Implementation Details
isTermuxUrl(url)deleteDirOrFile(url, type)(PR name and description are AI generated (Gemini 3.6 Flash))