mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor: remove the warning of unused variable, fix #300
This commit is contained in:
parent
2df1dae5af
commit
52e0746f30
1 changed files with 52 additions and 52 deletions
|
|
@ -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
|
// 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)]
|
#[allow(clippy::collapsible_else_if)]
|
||||||
pub fn permissions(permissions: Permissions) -> Option<String> {
|
pub fn permissions(permissions: Permissions) -> Option<String> {
|
||||||
#[cfg(windows)]
|
use std::os::unix::prelude::PermissionsExt;
|
||||||
return None;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
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};
|
||||||
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();
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
let mut s = String::with_capacity(10);
|
||||||
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',
|
||||||
|
_ => '-',
|
||||||
|
});
|
||||||
|
|
||||||
// File type
|
// Owner
|
||||||
s.push(match m & S_IFMT {
|
s.push(if m & S_IRUSR != 0 { 'r' } else { '-' });
|
||||||
S_IFBLK => 'b',
|
s.push(if m & S_IWUSR != 0 { 'w' } else { '-' });
|
||||||
S_IFCHR => 'c',
|
s.push(if m & S_IXUSR != 0 {
|
||||||
S_IFDIR => 'd',
|
if m & S_ISUID != 0 { 's' } else { 'x' }
|
||||||
S_IFIFO => 'p',
|
} else {
|
||||||
S_IFLNK => 'l',
|
if m & S_ISUID != 0 { 'S' } else { '-' }
|
||||||
S_IFSOCK => 's',
|
});
|
||||||
_ => '-',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Owner
|
// Group
|
||||||
s.push(if m & S_IRUSR != 0 { 'r' } else { '-' });
|
s.push(if m & S_IRGRP != 0 { 'r' } else { '-' });
|
||||||
s.push(if m & S_IWUSR != 0 { 'w' } else { '-' });
|
s.push(if m & S_IWGRP != 0 { 'w' } else { '-' });
|
||||||
s.push(if m & S_IXUSR != 0 {
|
s.push(if m & S_IXGRP != 0 {
|
||||||
if m & S_ISUID != 0 { 's' } else { 'x' }
|
if m & S_ISGID != 0 { 's' } else { 'x' }
|
||||||
} else {
|
} else {
|
||||||
if m & S_ISUID != 0 { 'S' } else { '-' }
|
if m & S_ISGID != 0 { 'S' } else { '-' }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Group
|
// Other
|
||||||
s.push(if m & S_IRGRP != 0 { 'r' } else { '-' });
|
s.push(if m & S_IROTH != 0 { 'r' } else { '-' });
|
||||||
s.push(if m & S_IWGRP != 0 { 'w' } else { '-' });
|
s.push(if m & S_IWOTH != 0 { 'w' } else { '-' });
|
||||||
s.push(if m & S_IXGRP != 0 {
|
s.push(if m & S_IXOTH != 0 {
|
||||||
if m & S_ISGID != 0 { 's' } else { 'x' }
|
if m & S_ISVTX != 0 { 't' } else { 'x' }
|
||||||
} else {
|
} else {
|
||||||
if m & S_ISGID != 0 { 'S' } else { '-' }
|
if m & S_ISVTX != 0 { 'T' } else { '-' }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Other
|
Some(s)
|
||||||
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
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the max common root of a list of files
|
// Find the max common root of a list of files
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue