diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..3450fc4 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +max_width = 80 +wrap_comments = true diff --git a/src/dir.rs b/src/dir.rs index f7c7c42..94d971c 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -93,7 +93,10 @@ impl TrashDir { } } -pub struct TrashDirIter(PathBuf, Box>>); +pub struct TrashDirIter( + PathBuf, + Box>>, +); impl Iterator for TrashDirIter { type Item = Result; @@ -126,6 +129,9 @@ impl Iterator for TrashDirIter { &name.as_bytes()[..name.len() - b".trashinfo".len()], )) }; - Some(TrashInfo::from_files(entry.path(), deleted_path).map_err(Error::from)) + Some( + TrashInfo::from_files(entry.path(), deleted_path) + .map_err(Error::from), + ) } } diff --git a/src/info.rs b/src/info.rs index 7fb09f7..8bfee41 100644 --- a/src/info.rs +++ b/src/info.rs @@ -62,7 +62,9 @@ impl TrashInfo { // first line must be "[Trash Info]" if i == 0 { if line != "[Trash Info]" { - return Err(Error::BadTrashInfo(TrashInfoError::MissingHeader)); + return Err(Error::BadTrashInfo( + TrashInfoError::MissingHeader, + )); } else { continue; } @@ -71,12 +73,14 @@ impl TrashInfo { if let Some((key, value)) = parse_key_value(&line) { match key { "Path" => { - let value = percent_decode(value.as_bytes()).collect::>(); + let value = percent_decode(value.as_bytes()) + .collect::>(); let value = PathBuf::from(OsStr::from_bytes(&value)); path = Some(value) } "DeletionDate" => { - let date = Local.datetime_from_str(value, DATE_FORMAT)?; + let date = + Local.datetime_from_str(value, DATE_FORMAT)?; deletion_date = Some(date) } _ => continue, @@ -88,12 +92,16 @@ impl TrashInfo { let path = match path { Some(path) => path, - None => return Err(Error::BadTrashInfo(TrashInfoError::MissingPath)), + None => { + return Err(Error::BadTrashInfo(TrashInfoError::MissingPath)) + } }; let deletion_date = match deletion_date { Some(deletion_date) => deletion_date, - None => return Err(Error::BadTrashInfo(TrashInfoError::MissingDate)), + None => { + return Err(Error::BadTrashInfo(TrashInfoError::MissingDate)) + } }; Ok(TrashInfo { diff --git a/src/main.rs b/src/main.rs index f86f323..dedbd73 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,9 @@ extern crate anyhow; use anyhow::Result; -use garbage::ops::{self, EmptyOptions, ListOptions, PutOptions, RestoreOptions}; +use garbage::ops::{ + self, EmptyOptions, ListOptions, PutOptions, RestoreOptions, +}; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/src/ops/put.rs b/src/ops/put.rs index a45bdbc..2311515 100644 --- a/src/ops/put.rs +++ b/src/ops/put.rs @@ -68,7 +68,8 @@ pub fn put(options: PutOptions) -> Result<()> { ensure!( !(utils::into_absolute(&path)? == current_dir.as_path() || (current_dir.parent().is_some() - && utils::into_absolute(&path)? == current_dir.parent().unwrap())), + && utils::into_absolute(&path)? + == current_dir.parent().unwrap())), Error::CannotTrashDotDirs ); @@ -129,7 +130,8 @@ impl DeletionStrategy { // try to use the $topdir/.Trash-$uid directory if should_use_topdir_trash_uid(&target_mount) { - let topdir_trash_uid = target_mount.join(format!(".Trash-{}", utils::get_uid())); + let topdir_trash_uid = + target_mount.join(format!(".Trash-{}", utils::get_uid())); let trash_dir = TrashDir::from(topdir_trash_uid); trash_dir.create()?; return Ok(DeletionStrategy::MoveTo(trash_dir)); @@ -151,7 +153,11 @@ impl DeletionStrategy { } /// The actual deletion happens here - pub fn delete(&self, target: impl AsRef, options: &PutOptions) -> Result<()> { + pub fn delete( + &self, + target: impl AsRef, + options: &PutOptions, + ) -> Result<()> { let target = target.as_ref(); // this will be None if target isn't a symlink diff --git a/src/utils.rs b/src/utils.rs index ccd62c4..48c514a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -25,7 +25,10 @@ pub fn get_uid() -> u64 { } /// This function recursively copies all the contents of src into dst. -pub fn recursive_copy(src: impl AsRef, dst: impl AsRef) -> Result<()> { +pub fn recursive_copy( + src: impl AsRef, + dst: impl AsRef, +) -> Result<()> { let src = src.as_ref(); let dst = dst.as_ref(); @@ -59,7 +62,10 @@ pub fn recursive_copy(src: impl AsRef, dst: impl AsRef) -> Result<() pub fn percent_encode(path: impl AsRef) -> String { let path = path.as_ref(); path.iter() - .map(|segment| percent_encoding::percent_encode(segment.as_bytes(), MASK).to_string()) + .map(|segment| { + percent_encoding::percent_encode(segment.as_bytes(), MASK) + .to_string() + }) .collect::>() .join(&MAIN_SEPARATOR.to_string()) }