From e46c2532f89112fab7a3a4353bef0ee2c594b209 Mon Sep 17 00:00:00 2001 From: rabite Date: Sat, 20 Apr 2019 18:59:41 +0200 Subject: use libraryized pathbuftools --- Cargo.lock | 56 ++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 ++- src/file_browser.rs | 3 ++- src/files.rs | 70 +---------------------------------------------------- src/main.rs | 1 + 5 files changed, 62 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7976562..e8766fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,6 +109,14 @@ dependencies = [ "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "constant_time_eq" version = "0.1.3" @@ -145,6 +153,16 @@ dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dirs-2" version = "1.1.0" @@ -252,6 +270,7 @@ dependencies = [ "notify 4.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "osstrtools 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parse-ansi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "pathbuftools 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "signal-notify 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "systemstat 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -505,6 +524,14 @@ dependencies = [ "regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pathbuftools" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "petgraph" version = "0.4.13" @@ -555,6 +582,19 @@ name = "rand_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rayon" version = "1.0.3" @@ -608,6 +648,17 @@ dependencies = [ "redox_syscall 0.1.53 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "redox_users" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.53 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "regex" version = "1.1.5" @@ -850,10 +901,12 @@ dependencies = [ "checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83" "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" +"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" +"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" "checksum dirs-2 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50b7e2b65c73137ec48935d50a5ae89b03150df566b7e14a1371df044e76765c" "checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" @@ -896,18 +949,21 @@ dependencies = [ "checksum parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "149d8f5b97f3c1133e3cfcd8886449959e856b557ff281e292b733d7c69e005e" "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum parse-ansi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "50c48b4d524f8a10bf6ab37dc0b7583f17c8ec88b617b364ddfc3baee4dcf878" +"checksum pathbuftools 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "908eefc77ffb9f995c7eb707eed61e66ef34fa66a735673517e65a34da3ef7a0" "checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f" "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" "checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" +"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" "checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473" "checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.53 (registry+https://github.com/rust-lang/crates.io-index)" = "53848511b7ee6eb9d5c3db48481aaa5779b38fc0131bc133c98cb4f2b2411928" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum redox_users 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "214a97e49be64fd2c86f568dd0cb2c757d2cc53de95b273b6ad0a1c908482f26" +"checksum redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe5204c3a17e97dde73f285d49be585df59ed84b50a872baf416e73b62c3828" "checksum regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "559008764a17de49a3146b234641644ed37d118d1ef641a0bb573d146edc6ce0" "checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" diff --git a/Cargo.toml b/Cargo.toml index f69db59..995ed25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,8 @@ notify = "4.0.9" parse-ansi = "0.1.6" signal-notify = "0.1.3" systemstat = "0.1.4" -osstrtools = "0.1.0" +osstrtools = "0.1" +pathbuftools = "0.1" #[profile.release] diff --git a/src/file_browser.rs b/src/file_browser.rs index 4554e4d..b74cb0d 100644 --- a/src/file_browser.rs +++ b/src/file_browser.rs @@ -1,4 +1,5 @@ use termion::event::Key; +use pathbuftools::PathBufTools; use std::io::Write; use std::sync::{Arc, Mutex, RwLock}; @@ -6,7 +7,7 @@ use std::path::PathBuf; use std::ffi::OsString; use std::collections::HashSet; -use crate::files::{File, Files, PathBufExt}; +use crate::files::{File, Files}; use crate::fscache::FsCache; use crate::listview::ListView; use crate::hbox::HBox; diff --git a/src/files.rs b/src/files.rs index c240920..a3cd0ab 100644 --- a/src/files.rs +++ b/src/files.rs @@ -6,8 +6,6 @@ use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex, RwLock}; use std::sync::mpsc::Sender; use std::hash::{Hash, Hasher}; -use std::os::unix::ffi::{OsStringExt, OsStrExt}; -use std::ffi::{OsStr, OsString}; use lscolors::LsColors; use tree_magic; @@ -20,6 +18,7 @@ use failure::Error; use notify::DebouncedEvent; use rayon::{ThreadPool, ThreadPoolBuilder}; use alphanumeric_sort::compare_str; +use pathbuftools::PathBufTools; use crate::fail::{HResult, HError, ErrorLog}; use crate::dirty::{AsyncDirtyBit, DirtyBit, Dirtyable}; @@ -997,70 +996,3 @@ impl File { self.path.short_string() } } - - -pub trait PathBufExt { - fn short_path(&self) -> PathBuf; - fn short_string(&self) -> String; - fn name_starts_with(&self, pat: &str) -> bool; - fn quoted_file_name(&self) -> Option; - fn quoted_path(&self) -> OsString; -} - -impl PathBufExt for PathBuf { - fn short_path(&self) -> PathBuf { - if let Ok(home) = crate::paths::home_path() { - if let Ok(short) = self.strip_prefix(home) { - let mut path = PathBuf::from("~"); - path.push(short); - return path - } - } - return self.clone(); - } - - fn short_string(&self) -> String { - self.short_path().to_string_lossy().to_string() - } - - fn name_starts_with(&self, pat: &str) -> bool { - if let Some(name) = self.file_name() { - let nbytes = name.as_bytes(); - let pbytes = pat.as_bytes(); - - if nbytes.starts_with(pbytes) { - return true; - } else { - return false; - } - } - false - } - - fn quoted_file_name(&self) -> Option { - if let Some(name) = self.file_name() { - let mut name = name.as_bytes().to_vec(); - let mut quote = "\"".as_bytes().to_vec(); - let mut quoted = vec![]; - quoted.append(&mut quote.clone()); - quoted.append(&mut name); - quoted.append(&mut quote); - - let quoted_name = OsStr::from_bytes("ed).to_os_string(); - return Some(quoted_name); - } - None - } - - fn quoted_path(&self) -> OsString { - let mut path = self.clone().into_os_string().into_vec(); - let mut quote = "\"".as_bytes().to_vec(); - - let mut quoted = vec![]; - quoted.append(&mut quote.clone()); - quoted.append(&mut path); - quoted.append(&mut quote); - - OsString::from_vec(quoted) - } -} diff --git a/src/main.rs b/src/main.rs index ea3d908..837a9ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,7 @@ extern crate signal_notify; extern crate tree_magic; extern crate systemstat; extern crate osstrtools; +extern crate pathbuftools; use failure::Fail; -- cgit v1.2.3