diff options
-rw-r--r-- | src/commands/bulk_rename.rs | 3 | ||||
-rw-r--r-- | src/commands/set_mode.rs | 2 | ||||
-rw-r--r-- | src/util/format.rs | 2 | ||||
-rw-r--r-- | src/util/unix.rs | 23 |
4 files changed, 16 insertions, 14 deletions
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs index 4171b01..1b1ffb4 100644 --- a/src/commands/bulk_rename.rs +++ b/src/commands/bulk_rename.rs @@ -30,7 +30,7 @@ pub fn _bulk_rename(context: &mut JoshutoContext) -> JoshutoResult<()> { rand::thread_rng() .sample_iter(&rand::distributions::Alphanumeric) .take(10) - .for_each(|ch| rand_str.push(ch)); + .for_each(|ch| rand_str.push(ch as char)); /* create this file in a temporary folder */ let mut file_path = path::PathBuf::from("/tmp"); @@ -43,6 +43,7 @@ pub fn _bulk_rename(context: &mut JoshutoContext) -> JoshutoResult<()> { None => vec![], } }; + { let mut file = std::fs::File::create(&file_path)?; for path in paths.iter() { diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs index a13cad6..8d443ea 100644 --- a/src/commands/set_mode.rs +++ b/src/commands/set_mode.rs @@ -45,7 +45,7 @@ pub fn set_mode(context: &mut JoshutoContext, backend: &mut TuiBackend) -> Joshu let user_input = match entry { Some(entry) => { let mode = entry.metadata.permissions_ref().mode(); - let mode_string = unix::stringify_mode(mode); + let mode_string = unix::mode_to_string(mode); TuiTextField::default() .prompt(":") .prefix(PREFIX) 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; } |