Fix clippy warnings
This commit is contained in:
parent
78fcdec05a
commit
e384cfd31b
10 changed files with 14 additions and 24 deletions
|
@ -5,7 +5,7 @@ authors = ["Michael Zhang <mail@mzhang.io>"]
|
||||||
description = "cli tool for interacting with the freedesktop trashcan"
|
description = "cli tool for interacting with the freedesktop trashcan"
|
||||||
repository = "https://git.sr.ht/~iptq/garbage"
|
repository = "https://git.sr.ht/~iptq/garbage"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "garbage"
|
name = "garbage"
|
||||||
|
|
|
@ -36,7 +36,7 @@ impl TrashDir {
|
||||||
/// If the option is None, then the home trash will be selected instead.
|
/// If the option is None, then the home trash will be selected instead.
|
||||||
pub fn from_opt(opt: Option<impl AsRef<Path>>) -> Self {
|
pub fn from_opt(opt: Option<impl AsRef<Path>>) -> Self {
|
||||||
opt.map(|path| TrashDir::from(path.as_ref().to_path_buf()))
|
opt.map(|path| TrashDir::from(path.as_ref().to_path_buf()))
|
||||||
.unwrap_or_else(|| TrashDir::get_home_trash())
|
.unwrap_or_else(TrashDir::get_home_trash)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Actually create the directory on disk corresponding to this trash
|
/// Actually create the directory on disk corresponding to this trash
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub struct MultipleErrors(Vec<Error>);
|
||||||
|
|
||||||
impl fmt::Display for MultipleErrors {
|
impl fmt::Display for MultipleErrors {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
writeln!(f, "")?;
|
writeln!(f)?;
|
||||||
for err in self.0.iter() {
|
for err in self.0.iter() {
|
||||||
writeln!(f, "- {}", err)?;
|
writeln!(f, "- {}", err)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,7 @@ const DATE_FORMAT: &str = "%Y-%m-%dT%H:%M:%S";
|
||||||
|
|
||||||
fn parse_key_value(line: &str) -> Option<(&str, &str)> {
|
fn parse_key_value(line: &str) -> Option<(&str, &str)> {
|
||||||
let mut parts = line.split('=').peekable();
|
let mut parts = line.split('=').peekable();
|
||||||
let key = if let Some(key) = parts.next() {
|
let key = parts.next()?;
|
||||||
key
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let value = &line[key.len() + 1..];
|
let value = &line[key.len() + 1..];
|
||||||
Some((key, value))
|
Some((key, value))
|
||||||
|
|
|
@ -5,11 +5,11 @@ extern crate log;
|
||||||
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
|
use clap::{crate_version, Parser};
|
||||||
use garbage::{
|
use garbage::{
|
||||||
ops::{self, EmptyOptions, ListOptions, PutOptions, RestoreOptions},
|
ops::{self, EmptyOptions, ListOptions, PutOptions, RestoreOptions},
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
use clap::{Parser, crate_version};
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(about, version = concat!(crate_version!(), "-", env!("GIT_HASH")), author)]
|
#[clap(about, version = concat!(crate_version!(), "-", env!("GIT_HASH")), author)]
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub fn empty(options: EmptyOptions) -> Result<()> {
|
||||||
// ignore files that were deleted after the cutoff (younger)
|
// ignore files that were deleted after the cutoff (younger)
|
||||||
.filter(|info| info.deletion_date <= cutoff)
|
.filter(|info| info.deletion_date <= cutoff)
|
||||||
.filter(|info| options.all || info.path.starts_with(¤t_dir))
|
.filter(|info| options.all || info.path.starts_with(¤t_dir))
|
||||||
.map(|info| -> Result<_> {
|
.try_for_each(|info| -> Result<_> {
|
||||||
if options.dry {
|
if options.dry {
|
||||||
println!("deleting {:?}", info.path);
|
println!("deleting {:?}", info.path);
|
||||||
} else {
|
} else {
|
||||||
|
@ -66,8 +66,7 @@ pub fn empty(options: EmptyOptions) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})?;
|
||||||
.collect::<Result<_>>()?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,7 @@ pub fn list(options: ListOptions) -> Result<()> {
|
||||||
.iter()?
|
.iter()?
|
||||||
.collect::<Result<Vec<_>>>()?
|
.collect::<Result<Vec<_>>>()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|info| {
|
.filter(|info| options.all || info.path.starts_with(¤t_dir))
|
||||||
if !options.all && !info.path.starts_with(¤t_dir) {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(info)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
files.sort_unstable_by_key(|info| info.deletion_date);
|
files.sort_unstable_by_key(|info| info.deletion_date);
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ impl DeletionStrategy {
|
||||||
let target = target.as_ref();
|
let target = target.as_ref();
|
||||||
let target_mount = MOUNTS
|
let target_mount = MOUNTS
|
||||||
.get_mount_point(target)
|
.get_mount_point(target)
|
||||||
.ok_or_else(|| PutError::CouldntFindMountPoint)?;
|
.ok_or(PutError::CouldntFindMountPoint)?;
|
||||||
|
|
||||||
// first, are we on the home mount?
|
// first, are we on the home mount?
|
||||||
if target_mount == *HOME_MOUNT {
|
if target_mount == *HOME_MOUNT {
|
||||||
|
@ -142,6 +142,7 @@ impl DeletionStrategy {
|
||||||
|
|
||||||
// try to use the $topdir/.Trash directory
|
// try to use the $topdir/.Trash directory
|
||||||
// NOTE: really wish i could break from if statements...
|
// NOTE: really wish i could break from if statements...
|
||||||
|
#[allow(clippy::never_loop)]
|
||||||
'topdir: while should_use_topdir_trash(&target_mount) {
|
'topdir: while should_use_topdir_trash(&target_mount) {
|
||||||
let topdir_trash_dir = target_mount
|
let topdir_trash_dir = target_mount
|
||||||
.join(".Trash")
|
.join(".Trash")
|
||||||
|
@ -313,5 +314,5 @@ fn should_use_topdir_trash_uid(path: impl AsRef<Path>) -> bool {
|
||||||
Err(_) => return false,
|
Err(_) => return false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return true;
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub fn restore(options: RestoreOptions) -> Result<()> {
|
||||||
files
|
files
|
||||||
};
|
};
|
||||||
|
|
||||||
if files.len() == 0 {
|
if files.is_empty() {
|
||||||
return Err(Error::NoFilesInThisDirectory(
|
return Err(Error::NoFilesInThisDirectory(
|
||||||
trash_dir.path().to_path_buf(),
|
trash_dir.path().to_path_buf(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub fn recursive_copy(
|
||||||
let relative_path = path.strip_prefix(src)?;
|
let relative_path = path.strip_prefix(src)?;
|
||||||
|
|
||||||
// this must be the root
|
// this must be the root
|
||||||
if let None = relative_path.file_name() {
|
if relative_path.file_name().is_none() {
|
||||||
fs::create_dir(dst)?;
|
fs::create_dir(dst)?;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ pub fn percent_encode(path: impl AsRef<Path>) -> String {
|
||||||
.join(&MAIN_SEPARATOR.to_string())
|
.join(&MAIN_SEPARATOR.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn concat_os_str_iter<'a>(ss: &Vec<&'a OsStr>) -> OsString {
|
pub(crate) fn concat_os_str_iter(ss: &[&OsStr]) -> OsString {
|
||||||
let mut len = 0;
|
let mut len = 0;
|
||||||
for s in ss {
|
for s in ss {
|
||||||
len += s.len();
|
len += s.len();
|
||||||
|
|
Loading…
Reference in a new issue