From 12bd67853929f2e6e4e26b7f863e96371ddc84bb Mon Sep 17 00:00:00 2001 From: sxyazi Date: Tue, 7 Nov 2023 09:40:45 +0800 Subject: [PATCH] .. --- yazi-plugin/src/bindings/files.rs | 9 ++++++++- yazi-shared/src/fs.rs | 9 ++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/yazi-plugin/src/bindings/files.rs b/yazi-plugin/src/bindings/files.rs index 974d9858..ca4bb568 100644 --- a/yazi-plugin/src/bindings/files.rs +++ b/yazi-plugin/src/bindings/files.rs @@ -73,7 +73,14 @@ impl Files { reg.add_field_method_get("accessed", |_, me| { Ok(me.accessed.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok())) }); - reg.add_method("permissions", |_, me, ()| Ok(yazi_shared::permissions(me.permissions))); + reg.add_method("permissions", |_, me, ()| { + Ok( + #[cfg(unix)] + Some(yazi_shared::permissions(me.permissions)), + #[cfg(windows)] + None, + ) + }); // Extension reg.add_field_method_get("name", |_, me| { diff --git a/yazi-shared/src/fs.rs b/yazi-shared/src/fs.rs index 4c4a8890..cfd1f6d7 100644 --- a/yazi-shared/src/fs.rs +++ b/yazi-shared/src/fs.rs @@ -91,15 +91,10 @@ pub fn copy_with_progress(from: &Path, to: &Path) -> mpsc::Receiver Option { None } - // Convert a file mode to a string representation #[cfg(unix)] #[allow(clippy::collapsible_else_if)] -pub fn permissions(mode: u32) -> Option { +pub fn permissions(mode: u32) -> String { use libc::{mode_t, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFSOCK, S_IRGRP, S_IROTH, S_IRUSR, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR}; let mut s = String::with_capacity(10); @@ -143,7 +138,7 @@ pub fn permissions(mode: u32) -> Option { if m & S_ISVTX != 0 { 'T' } else { '-' } }); - Some(s) + s } // Find the max common root of a list of files