From 70d983be98c4f5ad17073da3a77a7123ff4ddd04 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 27 Dec 2019 19:37:22 -0600 Subject: [PATCH] deny warnings --- src/lib.rs | 4 ++-- src/main.rs | 5 +++-- src/mounts.rs | 1 - src/ops/empty.rs | 1 - src/ops/put.rs | 10 ++++++---- src/utils.rs | 12 ++++++------ 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 36c85ca..958d847 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ +#![deny(warnings)] + #[macro_use] extern crate lazy_static; -#[macro_use] extern crate log; #[macro_use] extern crate anyhow; @@ -14,7 +15,6 @@ mod mounts; pub mod ops; mod utils; -use std::io; use std::path::PathBuf; use xdg::BaseDirectories; diff --git a/src/main.rs b/src/main.rs index e5491f3..fc55439 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ -#[macro_use] +#![deny(warnings)] + extern crate anyhow; use std::fs; @@ -75,7 +76,7 @@ fn run() -> Result<()> { paths, recursive, force, - } => ops::put(paths, recursive), + } => ops::put(paths, recursive, force), Command::Restore => { let home_trash = TrashDir::get_home_trash(); let mut files = home_trash diff --git a/src/mounts.rs b/src/mounts.rs index bdc39c0..091b6d8 100644 --- a/src/mounts.rs +++ b/src/mounts.rs @@ -1,5 +1,4 @@ use std::borrow::Cow; -use std::env; use std::ffi::OsStr; use std::fs::File; use std::io::Read; diff --git a/src/ops/empty.rs b/src/ops/empty.rs index 482e975..f2ea4c5 100644 --- a/src/ops/empty.rs +++ b/src/ops/empty.rs @@ -4,7 +4,6 @@ use anyhow::Result; use chrono::{Duration, Local}; use crate::TrashDir; -use crate::TrashInfo; pub fn empty(dry: bool, days: Option) -> Result<()> { let home_trash = TrashDir::get_home_trash(); diff --git a/src/ops/put.rs b/src/ops/put.rs index a3bed5a..f2a4828 100644 --- a/src/ops/put.rs +++ b/src/ops/put.rs @@ -4,7 +4,7 @@ use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; use anyhow::Result; -use chrono::{Duration, Local}; +use chrono::{Local}; use crate::utils; use crate::TrashDir; @@ -17,7 +17,7 @@ pub enum Error { CannotTrashDotDirs, } -pub fn put(paths: Vec, recursive: bool) -> Result<()> { +pub fn put(paths: Vec, _recursive: bool, _force: bool) -> Result<()> { let strategy = DeletionStrategy::Copy; for path in paths { if let Err(err) = strategy.delete(path) { @@ -28,6 +28,8 @@ pub fn put(paths: Vec, recursive: bool) -> Result<()> { Ok(()) } +// TODO: implement the other ones +#[allow(dead_code)] pub enum DeletionStrategy { Copy, Topdir, @@ -41,7 +43,7 @@ impl DeletionStrategy { path: impl AsRef, ) -> Option<(TrashDir, bool)> { let mount = mount.as_ref(); - let path = path.as_ref(); + let _path = path.as_ref(); // first, are we on the home mount? if mount == *HOME_MOUNT { @@ -155,7 +157,7 @@ impl DeletionStrategy { // copy the file over if copy { utils::recursive_copy(&target, &trash_file_path)?; - fs::remove_dir_all(&target); + fs::remove_dir_all(&target)?; } else { fs::rename(&target, &trash_file_path)?; } diff --git a/src/utils.rs b/src/utils.rs index 05f711d..4528452 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,10 +2,10 @@ use std::env; use std::fs; use std::path::{Path, PathBuf}; -use anyhow::Error; +use anyhow::Result; use walkdir::WalkDir; -pub fn into_absolute(path: impl AsRef) -> Result { +pub fn into_absolute(path: impl AsRef) -> Result { let path = path.as_ref(); Ok(if !path.is_absolute() { @@ -19,7 +19,7 @@ pub fn get_uid() -> u64 { unsafe { libc::getuid().into() } } -pub fn recursive_copy(src: impl AsRef, dst: impl AsRef) -> Result<(), Error> { +pub fn recursive_copy(src: impl AsRef, dst: impl AsRef) -> Result<()> { let src = src.as_ref(); let dst = dst.as_ref(); @@ -34,15 +34,15 @@ pub fn recursive_copy(src: impl AsRef, dst: impl AsRef) -> Result<() // this must be the root if let None = relative_path.file_name() { - fs::create_dir(dst); + fs::create_dir(dst)?; continue; } let target_name = dst.join(relative_path); if path.is_dir() { - fs::create_dir(&target_name); + fs::create_dir(&target_name)?; } else { - fs::copy(path, &target_name); + fs::copy(path, &target_name)?; } }