Fix clippy warnings

This commit is contained in:
Michael Zhang 2022-01-13 14:30:23 -06:00
parent 78fcdec05a
commit e384cfd31b
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
10 changed files with 14 additions and 24 deletions

View file

@ -5,7 +5,7 @@ authors = ["Michael Zhang <mail@mzhang.io>"]
description = "cli tool for interacting with the freedesktop trashcan"
repository = "https://git.sr.ht/~iptq/garbage"
license = "GPL-3.0"
edition = "2018"
edition = "2021"
[[bin]]
name = "garbage"

View file

@ -36,7 +36,7 @@ impl TrashDir {
/// If the option is None, then the home trash will be selected instead.
pub fn from_opt(opt: Option<impl AsRef<Path>>) -> Self {
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

View file

@ -71,7 +71,7 @@ pub struct MultipleErrors(Vec<Error>);
impl fmt::Display for MultipleErrors {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "")?;
writeln!(f)?;
for err in self.0.iter() {
writeln!(f, "- {}", err)?;
}

View file

@ -14,11 +14,7 @@ const DATE_FORMAT: &str = "%Y-%m-%dT%H:%M:%S";
fn parse_key_value(line: &str) -> Option<(&str, &str)> {
let mut parts = line.split('=').peekable();
let key = if let Some(key) = parts.next() {
key
} else {
return None;
};
let key = parts.next()?;
let value = &line[key.len() + 1..];
Some((key, value))

View file

@ -5,11 +5,11 @@ extern crate log;
use std::process::exit;
use clap::{crate_version, Parser};
use garbage::{
ops::{self, EmptyOptions, ListOptions, PutOptions, RestoreOptions},
Result,
};
use clap::{Parser, crate_version};
#[derive(Parser)]
#[clap(about, version = concat!(crate_version!(), "-", env!("GIT_HASH")), author)]

View file

@ -50,7 +50,7 @@ pub fn empty(options: EmptyOptions) -> Result<()> {
// ignore files that were deleted after the cutoff (younger)
.filter(|info| info.deletion_date <= cutoff)
.filter(|info| options.all || info.path.starts_with(&current_dir))
.map(|info| -> Result<_> {
.try_for_each(|info| -> Result<_> {
if options.dry {
println!("deleting {:?}", info.path);
} else {
@ -66,8 +66,7 @@ pub fn empty(options: EmptyOptions) -> Result<()> {
}
Ok(())
})
.collect::<Result<_>>()?;
})?;
Ok(())
}

View file

@ -29,13 +29,7 @@ pub fn list(options: ListOptions) -> Result<()> {
.iter()?
.collect::<Result<Vec<_>>>()?
.into_iter()
.filter_map(|info| {
if !options.all && !info.path.starts_with(&current_dir) {
None
} else {
Some(info)
}
})
.filter(|info| options.all || info.path.starts_with(&current_dir))
.collect::<Vec<_>>();
files.sort_unstable_by_key(|info| info.deletion_date);

View file

@ -132,7 +132,7 @@ impl DeletionStrategy {
let target = target.as_ref();
let target_mount = MOUNTS
.get_mount_point(target)
.ok_or_else(|| PutError::CouldntFindMountPoint)?;
.ok_or(PutError::CouldntFindMountPoint)?;
// first, are we on the home mount?
if target_mount == *HOME_MOUNT {
@ -142,6 +142,7 @@ impl DeletionStrategy {
// try to use the $topdir/.Trash directory
// NOTE: really wish i could break from if statements...
#[allow(clippy::never_loop)]
'topdir: while should_use_topdir_trash(&target_mount) {
let topdir_trash_dir = target_mount
.join(".Trash")
@ -313,5 +314,5 @@ fn should_use_topdir_trash_uid(path: impl AsRef<Path>) -> bool {
Err(_) => return false,
};
}
return true;
true
}

View file

@ -53,7 +53,7 @@ pub fn restore(options: RestoreOptions) -> Result<()> {
files
};
if files.len() == 0 {
if files.is_empty() {
return Err(Error::NoFilesInThisDirectory(
trash_dir.path().to_path_buf(),
));

View file

@ -60,7 +60,7 @@ pub fn recursive_copy(
let relative_path = path.strip_prefix(src)?;
// this must be the root
if let None = relative_path.file_name() {
if relative_path.file_name().is_none() {
fs::create_dir(dst)?;
continue;
}
@ -101,7 +101,7 @@ pub fn percent_encode(path: impl AsRef<Path>) -> 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;
for s in ss {
len += s.len();