1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

Make mode always u32 and switch to has_mode for StatRes fbs (#761)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2018-09-17 16:53:55 -07:00 committed by Ryan Dahl
parent 82d0638139
commit e3d634eb21
4 changed files with 11 additions and 9 deletions

View file

@ -70,6 +70,7 @@ class FileInfoImpl implements FileInfo {
const modified = this._msg.modified().toFloat64();
const accessed = this._msg.accessed().toFloat64();
const created = this._msg.created().toFloat64();
const hasMode = this._msg.hasMode();
const mode = this._msg.mode(); // negative for invalid mode (Windows)
this._isFile = this._msg.isFile();
@ -78,8 +79,8 @@ class FileInfoImpl implements FileInfo {
this.modified = modified ? modified : null;
this.accessed = accessed ? accessed : null;
this.created = created ? created : null;
// null if invalid mode (Windows)
this.mode = mode >= 0 ? mode & 0o7777 : null;
// null on Windows
this.mode = hasMode ? mode : null;
}
isFile() {

View file

@ -80,7 +80,7 @@ pub fn mkdir(path: &Path, perm: u32) -> std::io::Result<()> {
#[cfg(any(unix))]
fn set_dir_permission(builder: &mut DirBuilder, perm: u32) {
debug!("set dir perm to {}", perm);
builder.mode(perm);
builder.mode(perm & 0o777);
}
#[cfg(not(any(unix)))]

View file

@ -533,13 +533,13 @@ macro_rules! to_seconds {
}
#[cfg(any(unix))]
fn get_mode(perm: fs::Permissions) -> i32 {
(perm.mode() as i32)
fn get_mode(perm: fs::Permissions) -> u32 {
perm.mode()
}
#[cfg(not(any(unix)))]
fn get_mode(_perm: fs::Permissions) -> i32 {
-1
fn get_mode(_perm: fs::Permissions) -> u32 {
0
}
fn handle_stat(_d: *const DenoC, base: &msg::Base) -> Box<Op> {
@ -568,6 +568,7 @@ fn handle_stat(_d: *const DenoC, base: &msg::Base) -> Box<Op> {
accessed: to_seconds!(metadata.accessed()),
created: to_seconds!(metadata.created()),
mode: get_mode(metadata.permissions()),
has_mode: cfg!(target_family = "unix"),
..Default::default()
},
);

View file

@ -212,8 +212,8 @@ table StatRes {
modified:ulong;
accessed:ulong;
created:ulong;
mode: int = -1;
// negative mode for invalid (Windows); default to invalid
mode: uint;
has_mode: bool; // false on windows
}
root_type Base;