From e3d634eb218f48b7152b40d64b07ff2f0a58ca09 Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Mon, 17 Sep 2018 16:53:55 -0700 Subject: Make mode always u32 and switch to has_mode for StatRes fbs (#761) --- js/stat.ts | 5 +++-- src/fs.rs | 2 +- src/handlers.rs | 9 +++++---- src/msg.fbs | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/js/stat.ts b/js/stat.ts index 293d3aa69..a3ae553da 100644 --- a/js/stat.ts +++ b/js/stat.ts @@ -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() { diff --git a/src/fs.rs b/src/fs.rs index 33323b87b..efc8b91b1 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -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)))] diff --git a/src/handlers.rs b/src/handlers.rs index f13ecec9f..9c218827f 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -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 { @@ -568,6 +568,7 @@ fn handle_stat(_d: *const DenoC, base: &msg::Base) -> Box { accessed: to_seconds!(metadata.accessed()), created: to_seconds!(metadata.created()), mode: get_mode(metadata.permissions()), + has_mode: cfg!(target_family = "unix"), ..Default::default() }, ); diff --git a/src/msg.fbs b/src/msg.fbs index e80713236..37a48e2df 100644 --- a/src/msg.fbs +++ b/src/msg.fbs @@ -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; -- cgit v1.2.3