Fix lints
This commit is contained in:
parent
439e5d11d6
commit
11535a3fb6
|
@ -21,7 +21,7 @@ impl Run for Add {
|
||||||
let mut db = DatabaseFile::new(data_dir);
|
let mut db = DatabaseFile::new(data_dir);
|
||||||
let mut db = db.open()?;
|
let mut db = db.open()?;
|
||||||
|
|
||||||
for path in self.paths.iter() {
|
for path in &self.paths {
|
||||||
let path = if config::resolve_symlinks() {
|
let path = if config::resolve_symlinks() {
|
||||||
util::canonicalize(path)
|
util::canonicalize(path)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl Query {
|
||||||
print!("{}", selection);
|
print!("{}", selection);
|
||||||
} else {
|
} else {
|
||||||
let path = selection.get(5..).context("could not read selection from fzf")?;
|
let path = selection.get(5..).context("could not read selection from fzf")?;
|
||||||
print!("{}", path)
|
print!("{}", path);
|
||||||
}
|
}
|
||||||
} else if self.list {
|
} else if self.list {
|
||||||
let stdout = io::stdout();
|
let stdout = io::stdout();
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl Run for Remove {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
for path in self.paths.iter() {
|
for path in &self.paths {
|
||||||
if !db.remove(path) {
|
if !db.remove(path) {
|
||||||
let path_abs = util::resolve_path(path)?;
|
let path_abs = util::resolve_path(path)?;
|
||||||
let path_abs = util::path_to_str(&path_abs)?;
|
let path_abs = util::path_to_str(&path_abs)?;
|
||||||
|
|
|
@ -31,15 +31,8 @@ pub fn echo() -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exclude_dirs() -> Result<Vec<Pattern>> {
|
pub fn exclude_dirs() -> Result<Vec<Pattern>> {
|
||||||
match env::var_os("_ZO_EXCLUDE_DIRS") {
|
env::var_os("_ZO_EXCLUDE_DIRS").map_or_else(
|
||||||
Some(paths) => env::split_paths(&paths)
|
|| {
|
||||||
.map(|path| {
|
|
||||||
let pattern = path.to_str().context("invalid unicode in _ZO_EXCLUDE_DIRS")?;
|
|
||||||
Pattern::new(pattern)
|
|
||||||
.with_context(|| format!("invalid glob in _ZO_EXCLUDE_DIRS: {}", pattern))
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
None => {
|
|
||||||
let pattern = (|| {
|
let pattern = (|| {
|
||||||
let home = dirs::home_dir()?;
|
let home = dirs::home_dir()?;
|
||||||
let home = home.to_str()?;
|
let home = home.to_str()?;
|
||||||
|
@ -47,8 +40,17 @@ pub fn exclude_dirs() -> Result<Vec<Pattern>> {
|
||||||
Pattern::new(&home).ok()
|
Pattern::new(&home).ok()
|
||||||
})();
|
})();
|
||||||
Ok(pattern.into_iter().collect())
|
Ok(pattern.into_iter().collect())
|
||||||
}
|
},
|
||||||
}
|
|paths| {
|
||||||
|
env::split_paths(&paths)
|
||||||
|
.map(|path| {
|
||||||
|
let pattern = path.to_str().context("invalid unicode in _ZO_EXCLUDE_DIRS")?;
|
||||||
|
Pattern::new(pattern)
|
||||||
|
.with_context(|| format!("invalid glob in _ZO_EXCLUDE_DIRS: {}", pattern))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fzf_opts() -> Option<OsString> {
|
pub fn fzf_opts() -> Option<OsString> {
|
||||||
|
|
|
@ -51,7 +51,11 @@ impl<'file> Database<'file> {
|
||||||
|
|
||||||
match self.dirs.iter_mut().find(|dir| dir.path == path) {
|
match self.dirs.iter_mut().find(|dir| dir.path == path) {
|
||||||
None => {
|
None => {
|
||||||
self.dirs.push(Dir { path: path.to_string().into(), last_accessed: now, rank: 1.0 })
|
self.dirs.push(Dir {
|
||||||
|
path: path.to_string().into(),
|
||||||
|
last_accessed: now,
|
||||||
|
rank: 1.0,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Some(dir) => {
|
Some(dir) => {
|
||||||
dir.last_accessed = now;
|
dir.last_accessed = now;
|
||||||
|
|
32
src/util.rs
32
src/util.rs
|
@ -82,16 +82,13 @@ pub fn resolve_path<P: AsRef<Path>>(path: &P) -> Result<PathBuf> {
|
||||||
Some(Component::Prefix(prefix)) => match prefix.kind() {
|
Some(Component::Prefix(prefix)) => match prefix.kind() {
|
||||||
Prefix::Disk(drive_letter) => {
|
Prefix::Disk(drive_letter) => {
|
||||||
let disk = components.next().unwrap();
|
let disk = components.next().unwrap();
|
||||||
match components.peek() {
|
if components.peek() == Some(&Component::RootDir) {
|
||||||
Some(Component::RootDir) => {
|
let root = components.next().unwrap();
|
||||||
let root = components.next().unwrap();
|
stack.push(disk);
|
||||||
stack.push(disk);
|
stack.push(root);
|
||||||
stack.push(root);
|
} else {
|
||||||
}
|
base_path = get_drive_relative(drive_letter)?;
|
||||||
_ => {
|
stack.extend(base_path.components());
|
||||||
base_path = get_drive_relative(drive_letter)?;
|
|
||||||
stack.extend(base_path.components());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Prefix::VerbatimDisk(drive_letter) => {
|
Prefix::VerbatimDisk(drive_letter) => {
|
||||||
|
@ -120,17 +117,12 @@ pub fn resolve_path<P: AsRef<Path>>(path: &P) -> Result<PathBuf> {
|
||||||
stack.extend(base_path.components());
|
stack.extend(base_path.components());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if components.peek() == Some(&Component::RootDir) {
|
||||||
|
let root = components.next().unwrap();
|
||||||
|
stack.push(root);
|
||||||
} else {
|
} else {
|
||||||
match components.peek() {
|
base_path = current_dir()?;
|
||||||
Some(Component::RootDir) => {
|
stack.extend(base_path.components());
|
||||||
let root = components.next().unwrap();
|
|
||||||
stack.push(root);
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
base_path = current_dir()?;
|
|
||||||
stack.extend(base_path.components());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for component in components {
|
for component in components {
|
||||||
|
|
Loading…
Reference in New Issue