1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-12 00:54:02 -05:00

Properly track isFile, isSymlink, isDirectory (#4541)

* Properly track isFile, isSymlink, isDirectory

These don't exhaust all the possibilities, so none of them should be
defined as "neither of the others".

* empty
This commit is contained in:
dubiousjim 2020-03-31 13:46:25 -04:00 committed by GitHub
parent a86b07f2df
commit d4d0b5d90c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 1 deletions

View file

@ -25,6 +25,7 @@ export interface FileInfo {
// @internal // @internal
export class FileInfoImpl implements FileInfo { export class FileInfoImpl implements FileInfo {
readonly #isFile: boolean; readonly #isFile: boolean;
readonly #isDirectory: boolean;
readonly #isSymlink: boolean; readonly #isSymlink: boolean;
size: number; size: number;
modified: number | null; modified: number | null;
@ -53,6 +54,7 @@ export class FileInfoImpl implements FileInfo {
const { dev, ino, mode, nlink, uid, gid, rdev, blksize, blocks } = res; const { dev, ino, mode, nlink, uid, gid, rdev, blksize, blocks } = res;
this.#isFile = res.isFile; this.#isFile = res.isFile;
this.#isDirectory = res.isDirectory;
this.#isSymlink = res.isSymlink; this.#isSymlink = res.isSymlink;
this.size = res.size; this.size = res.size;
this.modified = modified ? modified : null; this.modified = modified ? modified : null;
@ -76,7 +78,7 @@ export class FileInfoImpl implements FileInfo {
} }
isDirectory(): boolean { isDirectory(): boolean {
return !this.#isFile && !this.#isSymlink; return this.#isDirectory;
} }
isSymlink(): boolean { isSymlink(): boolean {

View file

@ -4,6 +4,7 @@ import { FileInfo, FileInfoImpl } from "../../file_info.ts";
export interface StatResponse { export interface StatResponse {
isFile: boolean; isFile: boolean;
isDirectory: boolean;
isSymlink: boolean; isSymlink: boolean;
size: number; size: number;
modified: number; modified: number;

View file

@ -509,6 +509,7 @@ fn get_stat_json(
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
let mut json_val = json!({ let mut json_val = json!({
"isFile": metadata.is_file(), "isFile": metadata.is_file(),
"isDirectory": metadata.is_dir(),
"isSymlink": metadata.file_type().is_symlink(), "isSymlink": metadata.file_type().is_symlink(),
"size": metadata.len(), "size": metadata.len(),
// In seconds. Available on both Unix or Windows. // In seconds. Available on both Unix or Windows.