From 35a37341b318946c0a42fa437928776e7bc76c3b Mon Sep 17 00:00:00 2001 From: ztplz Date: Thu, 13 Sep 2018 12:26:20 +0800 Subject: [PATCH 1/4] change FileInfo to interface --- js/stat.ts | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/js/stat.ts b/js/stat.ts index 3193794a5d710..217a5694e649b 100644 --- a/js/stat.ts +++ b/js/stat.ts @@ -8,10 +8,9 @@ import { assert } from "./util"; * A FileInfo describes a file and is returned by `stat`, `lstat`, * `statSync`, `lstatSync`. */ -// TODO FileInfo should be an interface not a class. -export class FileInfo { - private readonly _isFile: boolean; - private readonly _isSymlink: boolean; +export interface FileInfo { + readonly _isFile: boolean; + readonly _isSymlink: boolean; /** The size of the file, in bytes. */ len: number; /** @@ -38,6 +37,34 @@ export class FileInfo { */ mode: number | null; + /** + * Returns whether this is info for a regular file. This result is mutually + * exclusive to `FileInfo.isDirectory` and `FileInfo.isSymlink`. + */ + isFile(): boolean; + + /** + * Returns whether this is info for a regular directory. This result is + * mutually exclusive to `FileInfo.isFile` and `FileInfo.isSymlink`. + */ + isDirectory(): boolean; + + /** + * Returns whether this is info for a symlink. This result is + * mutually exclusive to `FileInfo.isFile` and `FileInfo.isDirectory`. + */ + isSymlink(): boolean; +} + +class DenoFileInfo implements FileInfo { + _isFile: boolean; + _isSymlink: boolean; + len: number; + modified: number | null; + accessed: number | null; + created: number | null; + mode: number | null; + /* @internal */ constructor(private _msg: fbs.StatRes) { const modified = this._msg.modified().toFloat64(); @@ -54,26 +81,14 @@ export class FileInfo { this.mode = mode >= 0 ? mode : null; // null if invalid mode (Windows) } - /** - * Returns whether this is info for a regular file. This result is mutually - * exclusive to `FileInfo.isDirectory` and `FileInfo.isSymlink`. - */ isFile() { return this._isFile; } - /** - * Returns whether this is info for a regular directory. This result is - * mutually exclusive to `FileInfo.isFile` and `FileInfo.isSymlink`. - */ isDirectory() { return !this._isFile && !this._isSymlink; } - /** - * Returns whether this is info for a symlink. This result is - * mutually exclusive to `FileInfo.isFile` and `FileInfo.isDirectory`. - */ isSymlink() { return this._isSymlink; } @@ -147,5 +162,5 @@ function res(baseRes: null | fbs.Base): FileInfo { assert(fbs.Any.StatRes === baseRes!.msgType()); const res = new fbs.StatRes(); assert(baseRes!.msg(res) != null); - return new FileInfo(res); + return new DenoFileInfo(res); } From 5d36542e391f6c4c17d32c057250361247e71d3c Mon Sep 17 00:00:00 2001 From: ztplz Date: Thu, 13 Sep 2018 14:38:08 +0800 Subject: [PATCH 2/4] fix name --- js/stat.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/stat.ts b/js/stat.ts index 217a5694e649b..c7b12fe1aad5b 100644 --- a/js/stat.ts +++ b/js/stat.ts @@ -56,7 +56,7 @@ export interface FileInfo { isSymlink(): boolean; } -class DenoFileInfo implements FileInfo { +class FileInfoImpl implements FileInfo { _isFile: boolean; _isSymlink: boolean; len: number; @@ -162,5 +162,5 @@ function res(baseRes: null | fbs.Base): FileInfo { assert(fbs.Any.StatRes === baseRes!.msgType()); const res = new fbs.StatRes(); assert(baseRes!.msg(res) != null); - return new DenoFileInfo(res); + return new FileInfoImpl(res); } From a0f0d54effd3857e4e573f4db9419aabb2293bee Mon Sep 17 00:00:00 2001 From: ztplz Date: Fri, 14 Sep 2018 11:53:18 +0800 Subject: [PATCH 3/4] fix build error --- js/deno.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/deno.ts b/js/deno.ts index 187d0f27f7582..9b60d0d909762 100644 --- a/js/deno.ts +++ b/js/deno.ts @@ -1,12 +1,14 @@ // Copyright 2018 the Deno authors. All rights reserved. MIT license. // Public deno module. /// +import { FileInfo, statSync, lstatSync, stat, lstat } from './stat'; + export { env, exit, makeTempDirSync } from "./os"; export { mkdirSync, mkdir } from "./mkdir"; export { removeSync, remove, removeAllSync, removeAll } from "./remove"; export { readFileSync, readFile } from "./read_file"; export { renameSync, rename } from "./rename"; -export { FileInfo, statSync, lstatSync, stat, lstat } from "./stat"; +export { FileInfo, statSync, lstatSync, stat, lstat }; export { writeFileSync, writeFile } from "./write_file"; export { ErrorKind, DenoError } from "./errors"; export { libdeno } from "./libdeno"; From 0ed6991fdb36ad44367fa0309ab6d665b8d4dcb3 Mon Sep 17 00:00:00 2001 From: ztplz Date: Fri, 14 Sep 2018 15:47:52 +0800 Subject: [PATCH 4/4] fix build error --- js/deno.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/js/deno.ts b/js/deno.ts index 9b60d0d909762..7ff763e8d7443 100644 --- a/js/deno.ts +++ b/js/deno.ts @@ -1,14 +1,13 @@ // Copyright 2018 the Deno authors. All rights reserved. MIT license. // Public deno module. /// -import { FileInfo, statSync, lstatSync, stat, lstat } from './stat'; - -export { env, exit, makeTempDirSync } from "./os"; +export { env, exit } from "./os"; export { mkdirSync, mkdir } from "./mkdir"; +export { makeTempDirSync, makeTempDir } from "./make_temp_dir"; export { removeSync, remove, removeAllSync, removeAll } from "./remove"; export { readFileSync, readFile } from "./read_file"; export { renameSync, rename } from "./rename"; -export { FileInfo, statSync, lstatSync, stat, lstat }; +export { FileInfo, statSync, lstatSync, stat, lstat } from "./stat"; export { writeFileSync, writeFile } from "./write_file"; export { ErrorKind, DenoError } from "./errors"; export { libdeno } from "./libdeno";