Skip to content

Commit

Permalink
refactor: remove the warning of unused variable, fix #300
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Oct 23, 2023
1 parent 2df1dae commit 52e0746
Showing 1 changed file with 60 additions and 60 deletions.
120 changes: 60 additions & 60 deletions yazi-shared/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,68 +92,68 @@ pub fn copy_with_progress(from: &Path, to: &Path) -> mpsc::Receiver<Result<u64,
}

// Convert a file mode to a string representation
#[cfg(windows)]
#[allow(clippy::collapsible_else_if)]
pub fn permissions(_: Permissions) -> Option<String> { None }

// Convert a file mode to a string representation
#[cfg(unix)]
#[allow(clippy::collapsible_else_if)]
pub fn permissions(permissions: Permissions) -> Option<String> {
#[cfg(windows)]
return None;

#[cfg(unix)]
Some({
use std::os::unix::prelude::PermissionsExt;

use libc::{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};

#[cfg(target_os = "macos")]
let m = permissions.mode() as u16;
#[cfg(target_os = "freebsd")]
let m = permissions.mode() as u16;
#[cfg(target_os = "netbsd")]
let m = permissions.mode();
#[cfg(target_os = "linux")]
let m = permissions.mode();

let mut s = String::with_capacity(10);

// File type
s.push(match m & S_IFMT {
S_IFBLK => 'b',
S_IFCHR => 'c',
S_IFDIR => 'd',
S_IFIFO => 'p',
S_IFLNK => 'l',
S_IFSOCK => 's',
_ => '-',
});

// Owner
s.push(if m & S_IRUSR != 0 { 'r' } else { '-' });
s.push(if m & S_IWUSR != 0 { 'w' } else { '-' });
s.push(if m & S_IXUSR != 0 {
if m & S_ISUID != 0 { 's' } else { 'x' }
} else {
if m & S_ISUID != 0 { 'S' } else { '-' }
});

// Group
s.push(if m & S_IRGRP != 0 { 'r' } else { '-' });
s.push(if m & S_IWGRP != 0 { 'w' } else { '-' });
s.push(if m & S_IXGRP != 0 {
if m & S_ISGID != 0 { 's' } else { 'x' }
} else {
if m & S_ISGID != 0 { 'S' } else { '-' }
});

// Other
s.push(if m & S_IROTH != 0 { 'r' } else { '-' });
s.push(if m & S_IWOTH != 0 { 'w' } else { '-' });
s.push(if m & S_IXOTH != 0 {
if m & S_ISVTX != 0 { 't' } else { 'x' }
} else {
if m & S_ISVTX != 0 { 'T' } else { '-' }
});

s
})
use std::os::unix::prelude::PermissionsExt;

use libc::{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};

#[cfg(target_os = "macos")]
let m = permissions.mode() as u16;
#[cfg(target_os = "freebsd")]
let m = permissions.mode() as u16;
#[cfg(target_os = "netbsd")]
let m = permissions.mode();
#[cfg(target_os = "linux")]
let m = permissions.mode();

let mut s = String::with_capacity(10);

// File type
s.push(match m & S_IFMT {
S_IFBLK => 'b',
S_IFCHR => 'c',
S_IFDIR => 'd',
S_IFIFO => 'p',
S_IFLNK => 'l',
S_IFSOCK => 's',
_ => '-',
});

// Owner
s.push(if m & S_IRUSR != 0 { 'r' } else { '-' });
s.push(if m & S_IWUSR != 0 { 'w' } else { '-' });
s.push(if m & S_IXUSR != 0 {
if m & S_ISUID != 0 { 's' } else { 'x' }
} else {
if m & S_ISUID != 0 { 'S' } else { '-' }
});

// Group
s.push(if m & S_IRGRP != 0 { 'r' } else { '-' });
s.push(if m & S_IWGRP != 0 { 'w' } else { '-' });
s.push(if m & S_IXGRP != 0 {
if m & S_ISGID != 0 { 's' } else { 'x' }
} else {
if m & S_ISGID != 0 { 'S' } else { '-' }
});

// Other
s.push(if m & S_IROTH != 0 { 'r' } else { '-' });
s.push(if m & S_IWOTH != 0 { 'w' } else { '-' });
s.push(if m & S_IXOTH != 0 {
if m & S_ISVTX != 0 { 't' } else { 'x' }
} else {
if m & S_ISVTX != 0 { 'T' } else { '-' }
});

Some(s)
}

// Find the max common root of a list of files
Expand Down

0 comments on commit 52e0746

Please sign in to comment.