summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/ensure_symlink.ts6
-rw-r--r--fs/utils.ts24
-rw-r--r--fs/utils_test.ts10
3 files changed, 20 insertions, 20 deletions
diff --git a/fs/ensure_symlink.ts b/fs/ensure_symlink.ts
index fbb89948e..09452a8ce 100644
--- a/fs/ensure_symlink.ts
+++ b/fs/ensure_symlink.ts
@@ -2,7 +2,7 @@
import * as path from "./path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { exists, existsSync } from "./exists.ts";
-import { PathType, getFileInfoType } from "./utils.ts";
+import { getFileInfoType } from "./utils.ts";
const isWindows = Deno.platform.os === "win";
@@ -20,7 +20,7 @@ export async function ensureSymlink(src: string, dest: string): Promise<void> {
if (await exists(dest)) {
const destStatInfo = await Deno.lstat(dest);
const destFilePathType = getFileInfoType(destStatInfo);
- if (destFilePathType !== PathType.symlink) {
+ if (destFilePathType !== "symlink") {
throw new Error(
`Ensure path exists, expected 'symlink', got '${destFilePathType}'`
);
@@ -52,7 +52,7 @@ export function ensureSymlinkSync(src: string, dest: string): void {
if (existsSync(dest)) {
const destStatInfo = Deno.lstatSync(dest);
const destFilePathType = getFileInfoType(destStatInfo);
- if (destFilePathType !== PathType.symlink) {
+ if (destFilePathType !== "symlink") {
throw new Error(
`Ensure path exists, expected 'symlink', got '${destFilePathType}'`
);
diff --git a/fs/utils.ts b/fs/utils.ts
index 410e45909..06b4c295c 100644
--- a/fs/utils.ts
+++ b/fs/utils.ts
@@ -17,24 +17,24 @@ export function isSubdir(
const srcArray = src.split(sep);
const destArray = dest.split(sep);
- return srcArray.reduce((acc, current, i) => {
+ return srcArray.reduce((acc: boolean, current, i) => {
return acc && destArray[i] === current;
}, true);
}
-export enum PathType {
- file = "file",
- dir = "dir",
- symlink = "symlink"
-}
+export type PathType = "file" | "dir" | "symlink";
-/* Get a human readable file type string */
-export function getFileInfoType(fileInfo: Deno.FileInfo): PathType | null {
+/**
+ * Get a human readable file type string.
+ *
+ * @param fileInfo A FileInfo describes a file and is returned by `stat`, `lstat`
+ */
+export function getFileInfoType(fileInfo: Deno.FileInfo): PathType {
return fileInfo.isFile()
- ? PathType.file
+ ? "file"
: fileInfo.isDirectory()
- ? PathType.dir
+ ? "dir"
: fileInfo.isSymlink()
- ? PathType.symlink
- : null;
+ ? "symlink"
+ : undefined;
}
diff --git a/fs/utils_test.ts b/fs/utils_test.ts
index 9f8d10cb0..d833aa559 100644
--- a/fs/utils_test.ts
+++ b/fs/utils_test.ts
@@ -36,21 +36,21 @@ test(function _isSubdir() {
test(function _getFileInfoType() {
const pairs = [
- [path.join(testdataDir, "file_type_1"), PathType.file],
- [path.join(testdataDir, "file_type_dir_1"), PathType.dir]
+ [path.join(testdataDir, "file_type_1"), "file"],
+ [path.join(testdataDir, "file_type_dir_1"), "dir"]
];
pairs.forEach(function(p) {
const filePath = p[0] as string;
const type = p[1] as PathType;
switch (type) {
- case PathType.file:
+ case "file":
ensureFileSync(filePath);
break;
- case PathType.dir:
+ case "dir":
ensureDirSync(filePath);
break;
- case PathType.symlink:
+ case "symlink":
// TODO(axetroy): test symlink
break;
}