deny warnings
This commit is contained in:
parent
b55751f2c0
commit
70d983be98
6 changed files with 17 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
||||||
|
#![deny(warnings)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
extern crate log;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate anyhow;
|
extern crate anyhow;
|
||||||
|
@ -14,7 +15,6 @@ mod mounts;
|
||||||
pub mod ops;
|
pub mod ops;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use std::io;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use xdg::BaseDirectories;
|
use xdg::BaseDirectories;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#[macro_use]
|
#![deny(warnings)]
|
||||||
|
|
||||||
extern crate anyhow;
|
extern crate anyhow;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -75,7 +76,7 @@ fn run() -> Result<()> {
|
||||||
paths,
|
paths,
|
||||||
recursive,
|
recursive,
|
||||||
force,
|
force,
|
||||||
} => ops::put(paths, recursive),
|
} => ops::put(paths, recursive, force),
|
||||||
Command::Restore => {
|
Command::Restore => {
|
||||||
let home_trash = TrashDir::get_home_trash();
|
let home_trash = TrashDir::get_home_trash();
|
||||||
let mut files = home_trash
|
let mut files = home_trash
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::env;
|
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
|
@ -4,7 +4,6 @@ use anyhow::Result;
|
||||||
use chrono::{Duration, Local};
|
use chrono::{Duration, Local};
|
||||||
|
|
||||||
use crate::TrashDir;
|
use crate::TrashDir;
|
||||||
use crate::TrashInfo;
|
|
||||||
|
|
||||||
pub fn empty(dry: bool, days: Option<u32>) -> Result<()> {
|
pub fn empty(dry: bool, days: Option<u32>) -> Result<()> {
|
||||||
let home_trash = TrashDir::get_home_trash();
|
let home_trash = TrashDir::get_home_trash();
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use chrono::{Duration, Local};
|
use chrono::{Local};
|
||||||
|
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
use crate::TrashDir;
|
use crate::TrashDir;
|
||||||
|
@ -17,7 +17,7 @@ pub enum Error {
|
||||||
CannotTrashDotDirs,
|
CannotTrashDotDirs,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn put(paths: Vec<PathBuf>, recursive: bool) -> Result<()> {
|
pub fn put(paths: Vec<PathBuf>, _recursive: bool, _force: bool) -> Result<()> {
|
||||||
let strategy = DeletionStrategy::Copy;
|
let strategy = DeletionStrategy::Copy;
|
||||||
for path in paths {
|
for path in paths {
|
||||||
if let Err(err) = strategy.delete(path) {
|
if let Err(err) = strategy.delete(path) {
|
||||||
|
@ -28,6 +28,8 @@ pub fn put(paths: Vec<PathBuf>, recursive: bool) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: implement the other ones
|
||||||
|
#[allow(dead_code)]
|
||||||
pub enum DeletionStrategy {
|
pub enum DeletionStrategy {
|
||||||
Copy,
|
Copy,
|
||||||
Topdir,
|
Topdir,
|
||||||
|
@ -41,7 +43,7 @@ impl DeletionStrategy {
|
||||||
path: impl AsRef<Path>,
|
path: impl AsRef<Path>,
|
||||||
) -> Option<(TrashDir, bool)> {
|
) -> Option<(TrashDir, bool)> {
|
||||||
let mount = mount.as_ref();
|
let mount = mount.as_ref();
|
||||||
let path = path.as_ref();
|
let _path = path.as_ref();
|
||||||
|
|
||||||
// first, are we on the home mount?
|
// first, are we on the home mount?
|
||||||
if mount == *HOME_MOUNT {
|
if mount == *HOME_MOUNT {
|
||||||
|
@ -155,7 +157,7 @@ impl DeletionStrategy {
|
||||||
// copy the file over
|
// copy the file over
|
||||||
if copy {
|
if copy {
|
||||||
utils::recursive_copy(&target, &trash_file_path)?;
|
utils::recursive_copy(&target, &trash_file_path)?;
|
||||||
fs::remove_dir_all(&target);
|
fs::remove_dir_all(&target)?;
|
||||||
} else {
|
} else {
|
||||||
fs::rename(&target, &trash_file_path)?;
|
fs::rename(&target, &trash_file_path)?;
|
||||||
}
|
}
|
||||||
|
|
12
src/utils.rs
12
src/utils.rs
|
@ -2,10 +2,10 @@ use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Result;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
pub fn into_absolute(path: impl AsRef<Path>) -> Result<PathBuf, Error> {
|
pub fn into_absolute(path: impl AsRef<Path>) -> Result<PathBuf> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
|
|
||||||
Ok(if !path.is_absolute() {
|
Ok(if !path.is_absolute() {
|
||||||
|
@ -19,7 +19,7 @@ pub fn get_uid() -> u64 {
|
||||||
unsafe { libc::getuid().into() }
|
unsafe { libc::getuid().into() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recursive_copy(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<(), Error> {
|
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();
|
||||||
|
|
||||||
|
@ -34,15 +34,15 @@ pub fn recursive_copy(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()
|
||||||
|
|
||||||
// this must be the root
|
// this must be the root
|
||||||
if let None = relative_path.file_name() {
|
if let None = relative_path.file_name() {
|
||||||
fs::create_dir(dst);
|
fs::create_dir(dst)?;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let target_name = dst.join(relative_path);
|
let target_name = dst.join(relative_path);
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
fs::create_dir(&target_name);
|
fs::create_dir(&target_name)?;
|
||||||
} else {
|
} else {
|
||||||
fs::copy(path, &target_name);
|
fs::copy(path, &target_name)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue