Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs utils getFileInfoType() return undefined when not found #341

Merged
merged 7 commits into from Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions fs/utils.ts
Expand Up @@ -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 | void {
axetroy marked this conversation as resolved.
Show resolved Hide resolved
return fileInfo.isFile()
? PathType.file
? "file"
: fileInfo.isDirectory()
? PathType.dir
? "dir"
: fileInfo.isSymlink()
? PathType.symlink
: null;
? "symlink"
: undefined;
}
10 changes: 5 additions & 5 deletions fs/utils_test.ts
Expand Up @@ -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;
}
Expand Down