From cf26ffedb180df93644008b05129a30d10cd924a Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 4 Mar 2020 00:18:18 -0600 Subject: [PATCH] upd --- src/dir.rs | 8 ++++++++ src/ops/list.rs | 2 ++ src/ops/put.rs | 4 +--- src/ops/restore.rs | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/dir.rs b/src/dir.rs index 1bad7bd..97b3945 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -12,6 +12,7 @@ use crate::XDG; pub struct TrashDir(pub PathBuf); impl TrashDir { + /// Constructor for a new trash directory. pub fn from(path: impl AsRef) -> Self { TrashDir(path.as_ref().to_path_buf()) } @@ -27,11 +28,15 @@ impl TrashDir { TrashDir::from(XDG.get_data_home().join("Trash")) } + /// Create a trash directory from an optional path + /// + /// If the option is None, then the home trash will be selected instead. pub fn from_opt(opt: Option>) -> Self { opt.map(|path| TrashDir::from(path.as_ref().to_path_buf())) .unwrap_or_else(|| TrashDir::get_home_trash()) } + /// Actually create the directory on disk corresponding to this trash directory pub fn create(&self) -> Result<(), Error> { let path = &self.0; if !path.exists() { @@ -45,6 +50,7 @@ impl TrashDir { self.0.as_ref() } + /// Get the `files` directory pub fn files_dir(&self) -> Result { let target = self.0.join("files"); if !target.exists() { @@ -53,6 +59,7 @@ impl TrashDir { Ok(target) } + /// Get the `info` directory pub fn info_dir(&self) -> Result { let target = self.0.join("info"); if !target.exists() { @@ -61,6 +68,7 @@ impl TrashDir { Ok(target) } + /// Iterate over trash infos within this trash directory pub fn iter(&self) -> Result { let iter = WalkDir::new(&self.info_dir()?) .contents_first(true) diff --git a/src/ops/list.rs b/src/ops/list.rs index b4415d9..8cf2fe0 100644 --- a/src/ops/list.rs +++ b/src/ops/list.rs @@ -4,6 +4,7 @@ use anyhow::Result; use crate::TrashDir; +/// Options to pass to list #[derive(StructOpt)] pub struct ListOptions { /// The path to the trash directory to list. @@ -12,6 +13,7 @@ pub struct ListOptions { trash_dir: Option, } +/// List the contents of a trash directory pub fn list(options: ListOptions) -> Result<()> { let trash_dir = TrashDir::from_opt(options.trash_dir); diff --git a/src/ops/put.rs b/src/ops/put.rs index c2f84d7..9562b85 100644 --- a/src/ops/put.rs +++ b/src/ops/put.rs @@ -9,7 +9,7 @@ use chrono::Local; use crate::utils; use crate::{TrashDir, TrashInfo}; -use crate::{HOME_MOUNT, HOME_TRASH, MOUNTS}; +use crate::{HOME_MOUNT, MOUNTS}; #[derive(Debug, Error)] pub enum Error { @@ -275,7 +275,6 @@ fn should_use_topdir_trash(mount: impl AsRef) -> bool { } /// Can we use $topdir/.Trash-uid? - fn should_use_topdir_trash_uid(path: impl AsRef) -> bool { let path = path.as_ref(); if !path.exists() { @@ -284,6 +283,5 @@ fn should_use_topdir_trash_uid(path: impl AsRef) -> bool { Err(_) => return false, }; } - return true; } diff --git a/src/ops/restore.rs b/src/ops/restore.rs index 3d2f897..0b90f9e 100644 --- a/src/ops/restore.rs +++ b/src/ops/restore.rs @@ -6,6 +6,7 @@ use anyhow::Result; use crate::TrashDir; +/// Options to pass to restore #[derive(StructOpt)] pub struct RestoreOptions { /// The path to the trash directory to restore from. @@ -14,6 +15,7 @@ pub struct RestoreOptions { trash_dir: Option, } +/// Restore files from a trash directory pub fn restore(options: RestoreOptions) -> Result<()> { let trash_dir = TrashDir::from_opt(options.trash_dir);