Format code using max_width = 80 + wrap_comments = true
This commit is contained in:
parent
f676537096
commit
39690f873f
6 changed files with 43 additions and 13 deletions
2
rustfmt.toml
Normal file
2
rustfmt.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
max_width = 80
|
||||||
|
wrap_comments = true
|
10
src/dir.rs
10
src/dir.rs
|
@ -93,7 +93,10 @@ impl TrashDir {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TrashDirIter(PathBuf, Box<dyn Iterator<Item = walkdir::Result<DirEntry>>>);
|
pub struct TrashDirIter(
|
||||||
|
PathBuf,
|
||||||
|
Box<dyn Iterator<Item = walkdir::Result<DirEntry>>>,
|
||||||
|
);
|
||||||
|
|
||||||
impl Iterator for TrashDirIter {
|
impl Iterator for TrashDirIter {
|
||||||
type Item = Result<TrashInfo, Error>;
|
type Item = Result<TrashInfo, Error>;
|
||||||
|
@ -126,6 +129,9 @@ impl Iterator for TrashDirIter {
|
||||||
&name.as_bytes()[..name.len() - b".trashinfo".len()],
|
&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),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
src/info.rs
18
src/info.rs
|
@ -62,7 +62,9 @@ impl TrashInfo {
|
||||||
// first line must be "[Trash Info]"
|
// first line must be "[Trash Info]"
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if line != "[Trash Info]" {
|
if line != "[Trash Info]" {
|
||||||
return Err(Error::BadTrashInfo(TrashInfoError::MissingHeader));
|
return Err(Error::BadTrashInfo(
|
||||||
|
TrashInfoError::MissingHeader,
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -71,12 +73,14 @@ impl TrashInfo {
|
||||||
if let Some((key, value)) = parse_key_value(&line) {
|
if let Some((key, value)) = parse_key_value(&line) {
|
||||||
match key {
|
match key {
|
||||||
"Path" => {
|
"Path" => {
|
||||||
let value = percent_decode(value.as_bytes()).collect::<Vec<_>>();
|
let value = percent_decode(value.as_bytes())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
let value = PathBuf::from(OsStr::from_bytes(&value));
|
let value = PathBuf::from(OsStr::from_bytes(&value));
|
||||||
path = Some(value)
|
path = Some(value)
|
||||||
}
|
}
|
||||||
"DeletionDate" => {
|
"DeletionDate" => {
|
||||||
let date = Local.datetime_from_str(value, DATE_FORMAT)?;
|
let date =
|
||||||
|
Local.datetime_from_str(value, DATE_FORMAT)?;
|
||||||
deletion_date = Some(date)
|
deletion_date = Some(date)
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
|
@ -88,12 +92,16 @@ impl TrashInfo {
|
||||||
|
|
||||||
let path = match path {
|
let path = match path {
|
||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
None => return Err(Error::BadTrashInfo(TrashInfoError::MissingPath)),
|
None => {
|
||||||
|
return Err(Error::BadTrashInfo(TrashInfoError::MissingPath))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let deletion_date = match deletion_date {
|
let deletion_date = match deletion_date {
|
||||||
Some(deletion_date) => deletion_date,
|
Some(deletion_date) => deletion_date,
|
||||||
None => return Err(Error::BadTrashInfo(TrashInfoError::MissingDate)),
|
None => {
|
||||||
|
return Err(Error::BadTrashInfo(TrashInfoError::MissingDate))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(TrashInfo {
|
Ok(TrashInfo {
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
extern crate anyhow;
|
extern crate anyhow;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use garbage::ops::{self, EmptyOptions, ListOptions, PutOptions, RestoreOptions};
|
use garbage::ops::{
|
||||||
|
self, EmptyOptions, ListOptions, PutOptions, RestoreOptions,
|
||||||
|
};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
#[derive(StructOpt)]
|
#[derive(StructOpt)]
|
||||||
|
|
|
@ -68,7 +68,8 @@ pub fn put(options: PutOptions) -> Result<()> {
|
||||||
ensure!(
|
ensure!(
|
||||||
!(utils::into_absolute(&path)? == current_dir.as_path()
|
!(utils::into_absolute(&path)? == current_dir.as_path()
|
||||||
|| (current_dir.parent().is_some()
|
|| (current_dir.parent().is_some()
|
||||||
&& utils::into_absolute(&path)? == current_dir.parent().unwrap())),
|
&& utils::into_absolute(&path)?
|
||||||
|
== current_dir.parent().unwrap())),
|
||||||
Error::CannotTrashDotDirs
|
Error::CannotTrashDotDirs
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -129,7 +130,8 @@ impl DeletionStrategy {
|
||||||
|
|
||||||
// try to use the $topdir/.Trash-$uid directory
|
// try to use the $topdir/.Trash-$uid directory
|
||||||
if should_use_topdir_trash_uid(&target_mount) {
|
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);
|
let trash_dir = TrashDir::from(topdir_trash_uid);
|
||||||
trash_dir.create()?;
|
trash_dir.create()?;
|
||||||
return Ok(DeletionStrategy::MoveTo(trash_dir));
|
return Ok(DeletionStrategy::MoveTo(trash_dir));
|
||||||
|
@ -151,7 +153,11 @@ impl DeletionStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The actual deletion happens here
|
/// The actual deletion happens here
|
||||||
pub fn delete(&self, target: impl AsRef<Path>, options: &PutOptions) -> Result<()> {
|
pub fn delete(
|
||||||
|
&self,
|
||||||
|
target: impl AsRef<Path>,
|
||||||
|
options: &PutOptions,
|
||||||
|
) -> Result<()> {
|
||||||
let target = target.as_ref();
|
let target = target.as_ref();
|
||||||
|
|
||||||
// this will be None if target isn't a symlink
|
// this will be None if target isn't a symlink
|
||||||
|
|
10
src/utils.rs
10
src/utils.rs
|
@ -25,7 +25,10 @@ pub fn get_uid() -> u64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function recursively copies all the contents of src into dst.
|
/// This function recursively copies all the contents of src into dst.
|
||||||
pub fn recursive_copy(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()> {
|
pub fn recursive_copy(
|
||||||
|
src: impl AsRef<Path>,
|
||||||
|
dst: impl AsRef<Path>,
|
||||||
|
) -> Result<()> {
|
||||||
let src = src.as_ref();
|
let src = src.as_ref();
|
||||||
let dst = dst.as_ref();
|
let dst = dst.as_ref();
|
||||||
|
|
||||||
|
@ -59,7 +62,10 @@ pub fn recursive_copy(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()
|
||||||
pub fn percent_encode(path: impl AsRef<Path>) -> String {
|
pub fn percent_encode(path: impl AsRef<Path>) -> String {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
path.iter()
|
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::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(&MAIN_SEPARATOR.to_string())
|
.join(&MAIN_SEPARATOR.to_string())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue