summaryrefslogtreecommitdiff
path: root/std/fs/empty_dir.ts
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-02-02 19:05:46 +0800
committerGitHub <noreply@github.com>2021-02-02 12:05:46 +0100
commit6abf126c2a7a451cded8c6b5e6ddf1b69c84055d (patch)
treefd94c013a19fcb38954844085821ec1601c20e18 /std/fs/empty_dir.ts
parenta2b5d44f1aa9d64f448a2a3cc2001272e2f60b98 (diff)
chore: remove std directory (#9361)
This removes the std folder from the tree. Various parts of the tests are pretty tightly dependent on std (47 direct imports and 75 indirect imports, not counting the cli tests that use them as fixtures) so I've added std as a submodule for now.
Diffstat (limited to 'std/fs/empty_dir.ts')
-rw-r--r--std/fs/empty_dir.ts62
1 files changed, 0 insertions, 62 deletions
diff --git a/std/fs/empty_dir.ts b/std/fs/empty_dir.ts
deleted file mode 100644
index df73ad6b7..000000000
--- a/std/fs/empty_dir.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-import { join } from "../path/mod.ts";
-
-/**
- * Ensures that a directory is empty.
- * Deletes directory contents if the directory is not empty.
- * If the directory does not exist, it is created.
- * The directory itself is not deleted.
- * Requires the `--allow-read` and `--allow-write` flag.
- */
-export async function emptyDir(dir: string): Promise<void> {
- try {
- const items = [];
- for await (const dirEntry of Deno.readDir(dir)) {
- items.push(dirEntry);
- }
-
- while (items.length) {
- const item = items.shift();
- if (item && item.name) {
- const filepath = join(dir, item.name);
- await Deno.remove(filepath, { recursive: true });
- }
- }
- } catch (err) {
- if (!(err instanceof Deno.errors.NotFound)) {
- throw err;
- }
-
- // if not exist. then create it
- await Deno.mkdir(dir, { recursive: true });
- }
-}
-
-/**
- * Ensures that a directory is empty.
- * Deletes directory contents if the directory is not empty.
- * If the directory does not exist, it is created.
- * The directory itself is not deleted.
- * Requires the `--allow-read` and `--allow-write` flag.
- */
-export function emptyDirSync(dir: string): void {
- try {
- const items = [...Deno.readDirSync(dir)];
-
- // If the directory exists, remove all entries inside it.
- while (items.length) {
- const item = items.shift();
- if (item && item.name) {
- const filepath = join(dir, item.name);
- Deno.removeSync(filepath, { recursive: true });
- }
- }
- } catch (err) {
- if (!(err instanceof Deno.errors.NotFound)) {
- throw err;
- }
- // if not exist. then create it
- Deno.mkdirSync(dir, { recursive: true });
- return;
- }
-}