-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: fix broken link in README.md (#1154) * fix(react-native): fix for "<Intermediate Value>.stream is not a function" errors in React Native (#1156) * Added an error handler for cleanup after failed clone * chore: add comments * fix: add recursive delete helper & tests Co-authored-by: Xavier Francisco <xavier.n.francisco@gmail.com> Co-authored-by: Corbin Crutchley <crutchcorn@gmail.com>
- Loading branch information
1 parent
e63b4eb
commit b0f943a
Showing
3 changed files
with
107 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { join } from './join' | ||
|
||
/** | ||
* @param {object} args | ||
* @param {import('../models/FileSystem.js').FileSystem} args.fs | ||
* @param {string} args.dirname | ||
*/ | ||
export async function deleteRecursively({ fs, dirname }) { | ||
const filesToDelete = [] | ||
const directoriesToDelete = [] | ||
const pathsToTraverse = [dirname] | ||
|
||
while (pathsToTraverse.length > 0) { | ||
const path = pathsToTraverse.pop() | ||
|
||
if ((await fs._stat(path)).isDirectory()) { | ||
directoriesToDelete.push(path) | ||
pathsToTraverse.push( | ||
...(await fs.readdir(path)).map(subPath => join(path, subPath)) | ||
) | ||
} else { | ||
filesToDelete.push(path) | ||
} | ||
} | ||
|
||
for (const path of filesToDelete) { | ||
await fs.rm(path) | ||
} | ||
for (const path of directoriesToDelete.reverse()) { | ||
await fs.rmdir(path) | ||
} | ||
} |