summaryrefslogtreecommitdiff
path: root/fs/utils.ts
diff options
context:
space:
mode:
authorAxetroy <troy450409405@gmail.com>2019-04-07 09:01:23 +0800
committerRyan Dahl <ry@tinyclouds.org>2019-04-07 04:01:23 +0300
commitd6f808958f414315a09b3429cf0c4b5c258f1012 (patch)
treed2d60398319ba1bcd3f11216b258d835941ef45f /fs/utils.ts
parent9d1e24b67baf59d1d8b9bd1eb2a6c4135c6e7ca4 (diff)
fix: ensure exists file/dir must be the same type or it will throw error (denoland/deno_std#294)
Original: https://github.com/denoland/deno_std/commit/24f41f67bdbc9f426e3f9f03598a1010748d8200
Diffstat (limited to 'fs/utils.ts')
-rw-r--r--fs/utils.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/fs/utils.ts b/fs/utils.ts
index dd7ee5fa4..410e45909 100644
--- a/fs/utils.ts
+++ b/fs/utils.ts
@@ -21,3 +21,20 @@ export function isSubdir(
return acc && destArray[i] === current;
}, true);
}
+
+export enum PathType {
+ file = "file",
+ dir = "dir",
+ symlink = "symlink"
+}
+
+/* Get a human readable file type string */
+export function getFileInfoType(fileInfo: Deno.FileInfo): PathType | null {
+ return fileInfo.isFile()
+ ? PathType.file
+ : fileInfo.isDirectory()
+ ? PathType.dir
+ : fileInfo.isSymlink()
+ ? PathType.symlink
+ : null;
+}