1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -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 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 hasMode = this._msg.hasMode();
const mode = this._msg.mode(); // negative for invalid mode (Windows) const mode = this._msg.mode(); // negative for invalid mode (Windows)
this._isFile = this._msg.isFile(); this._isFile = this._msg.isFile();
@ -78,8 +79,8 @@ class FileInfoImpl implements 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;
// null if invalid mode (Windows) // null on Windows
this.mode = mode >= 0 ? mode & 0o7777 : null; this.mode = hasMode ? mode : null;
} }
isFile() { isFile() {

View file

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

View file

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

View file

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