mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Add unix-only mode
for FileInfo (#732)
This commit is contained in:
parent
1ffae65165
commit
26081a32df
3 changed files with 23 additions and 0 deletions
|
@ -8,6 +8,7 @@ import { assert } from "./util";
|
||||||
* A FileInfo describes a file and is returned by `stat`, `lstat`,
|
* A FileInfo describes a file and is returned by `stat`, `lstat`,
|
||||||
* `statSync`, `lstatSync`.
|
* `statSync`, `lstatSync`.
|
||||||
*/
|
*/
|
||||||
|
// TODO FileInfo should be an interface not a class.
|
||||||
export class FileInfo {
|
export class FileInfo {
|
||||||
private readonly _isFile: boolean;
|
private readonly _isFile: boolean;
|
||||||
private readonly _isSymlink: boolean;
|
private readonly _isSymlink: boolean;
|
||||||
|
@ -31,12 +32,18 @@ export class FileInfo {
|
||||||
* be available on all platforms.
|
* be available on all platforms.
|
||||||
*/
|
*/
|
||||||
created: number | null;
|
created: number | null;
|
||||||
|
/**
|
||||||
|
* The underlying raw st_mode bits that contain the standard Unix permissions
|
||||||
|
* for this file/directory. TODO Match behavior with Go on windows for mode.
|
||||||
|
*/
|
||||||
|
mode: number | null;
|
||||||
|
|
||||||
/* @internal */
|
/* @internal */
|
||||||
constructor(private _msg: fbs.StatRes) {
|
constructor(private _msg: fbs.StatRes) {
|
||||||
const modified = this._msg.modified().toFloat64();
|
const modified = this._msg.modified().toFloat64();
|
||||||
const accessed = this._msg.accessed().toFloat64();
|
const accessed = this._msg.accessed().toFloat64();
|
||||||
const created = this._msg.created().toFloat64();
|
const created = this._msg.created().toFloat64();
|
||||||
|
const mode = this._msg.mode(); // negative for invalid mode (Windows)
|
||||||
|
|
||||||
this._isFile = this._msg.isFile();
|
this._isFile = this._msg.isFile();
|
||||||
this._isSymlink = this._msg.isSymlink();
|
this._isSymlink = this._msg.isSymlink();
|
||||||
|
@ -44,6 +51,7 @@ export class FileInfo {
|
||||||
this.modified = modified ? modified : null;
|
this.modified = modified ? modified : null;
|
||||||
this.accessed = accessed ? accessed : null;
|
this.accessed = accessed ? accessed : null;
|
||||||
this.created = created ? created : null;
|
this.created = created ? created : null;
|
||||||
|
this.mode = mode >= 0 ? mode : null; // null if invalid mode (Windows)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,6 +15,8 @@ use msg;
|
||||||
use remove_dir_all::remove_dir_all;
|
use remove_dir_all::remove_dir_all;
|
||||||
use std;
|
use std;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
#[cfg(any(unix))]
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::UNIX_EPOCH;
|
use std::time::UNIX_EPOCH;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
@ -504,6 +506,16 @@ macro_rules! to_seconds {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(unix))]
|
||||||
|
fn get_mode(perm: fs::Permissions) -> i32 {
|
||||||
|
(perm.mode() as i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(unix)))]
|
||||||
|
fn get_mode(_perm: fs::Permissions) -> i32 {
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_stat(_d: *const DenoC, base: &msg::Base) -> Box<Op> {
|
fn handle_stat(_d: *const DenoC, base: &msg::Base) -> Box<Op> {
|
||||||
let msg = base.msg_as_stat().unwrap();
|
let msg = base.msg_as_stat().unwrap();
|
||||||
let cmd_id = base.cmd_id();
|
let cmd_id = base.cmd_id();
|
||||||
|
@ -529,6 +541,7 @@ fn handle_stat(_d: *const DenoC, base: &msg::Base) -> Box<Op> {
|
||||||
modified: to_seconds!(metadata.modified()),
|
modified: to_seconds!(metadata.modified()),
|
||||||
accessed: to_seconds!(metadata.accessed()),
|
accessed: to_seconds!(metadata.accessed()),
|
||||||
created: to_seconds!(metadata.created()),
|
created: to_seconds!(metadata.created()),
|
||||||
|
mode: get_mode(metadata.permissions()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -211,6 +211,8 @@ table StatRes {
|
||||||
modified:ulong;
|
modified:ulong;
|
||||||
accessed:ulong;
|
accessed:ulong;
|
||||||
created:ulong;
|
created:ulong;
|
||||||
|
mode: int = -1;
|
||||||
|
// negative mode for invalid (Windows); default to invalid
|
||||||
}
|
}
|
||||||
|
|
||||||
root_type Base;
|
root_type Base;
|
||||||
|
|
Loading…
Add table
Reference in a new issue