diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-12-20 17:57:59 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-12-20 17:57:59 -0500 |
commit | 8ff42dcc67a913b2b663455b84a5729022076a3d (patch) | |
tree | 41c3151c89927608322e8036f1d7b1fcb3571da1 /src/util | |
parent | 9891eebc5d993081086ef49954dce173db9fab99 (diff) |
fix char issue with bulk_rename
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/format.rs | 2 | ||||
-rw-r--r-- | src/util/unix.rs | 23 |
2 files changed, 13 insertions, 12 deletions
diff --git a/src/util/format.rs b/src/util/format.rs index e690513..e7231df 100644 --- a/src/util/format.rs +++ b/src/util/format.rs @@ -23,7 +23,7 @@ pub fn file_size_to_string(file_size: u64) -> String { } pub fn mode_to_string(mode: u32) -> String { - unix::stringify_mode(mode) + unix::mode_to_string(mode) } pub fn mtime_to_string(mtime: time::SystemTime) -> String { diff --git a/src/util/unix.rs b/src/util/unix.rs index b2105a9..65b12c9 100644 --- a/src/util/unix.rs +++ b/src/util/unix.rs @@ -1,3 +1,5 @@ +use phf::phf_map; + use std::path::Path; pub fn is_executable(mode: u32) -> bool { @@ -8,15 +10,15 @@ pub fn is_executable(mode: u32) -> bool { .any(|val| mode & (*val as u32) != 0) } -pub fn stringify_mode(mode: u32) -> String { +pub fn mode_to_string(mode: u32) -> String { const LIBC_FILE_VALS: [(libc::mode_t, char); 7] = [ - (libc::S_IFREG, '-'), - (libc::S_IFDIR, 'd'), - (libc::S_IFLNK, 'l'), - (libc::S_IFSOCK, 's'), - (libc::S_IFBLK, 'b'), - (libc::S_IFCHR, 'c'), - (libc::S_IFIFO, 'f'), + (libc::S_IFREG >> 9, '-'), + (libc::S_IFDIR >> 9, 'd'), + (libc::S_IFLNK >> 9, 'l'), + (libc::S_IFSOCK >> 9, 's'), + (libc::S_IFBLK >> 9, 'b'), + (libc::S_IFCHR >> 9, 'c'), + (libc::S_IFIFO >> 9, 'f'), ]; const LIBC_PERMISSION_VALS: [(libc::mode_t, char); 9] = [ @@ -30,13 +32,12 @@ pub fn stringify_mode(mode: u32) -> String { (libc::S_IWOTH, 'w'), (libc::S_IXOTH, 'x'), ]; - let mut mode_str: String = String::with_capacity(10); + let mut mode_str: String = String::with_capacity(10); let mode_shifted = mode >> 9; for (val, ch) in LIBC_FILE_VALS.iter() { - let val: u32 = (*val >> 9) as u32; - if mode_shifted & val == mode_shifted { + if mode_shifted == *val { mode_str.push(*ch); break; } |