~iptq/garbage

f7601628137618493348fa37edd982b2483771c6 — Michael Zhang 2 years ago 1835637
fix warnings
4 files changed, 18 insertions(+), 16 deletions(-)

M src/main.rs
M src/ops.rs
M src/trashdir.rs
M src/trashinfo.rs
M src/main.rs => src/main.rs +6 -3
@@ 15,6 15,7 @@ use std::path::PathBuf;
use structopt::StructOpt;
use xdg::BaseDirectories;

use crate::errors::Error;
use crate::trashdir::TrashDir;

lazy_static! {


@@ 50,14 51,14 @@ enum Command {

        /// -f to stay compatible with GNU rm
        #[structopt(long = "force", short = "f")]
        force: bool,
        _force: bool,
    },

    #[structopt(name = "restore")]
    Restore,
}

fn main() {
fn main() -> Result<(), Error> {
    env_logger::init();

    let cmd = Command::from_args();


@@ 120,10 121,12 @@ fn main() {
                Ok(i) if i < files.len() => {
                    let info = files.get(i).unwrap();
                    println!("moving {:?} to {:?}", &info.deleted_path, &info.path);
                    fs::rename(&info.deleted_path, &info.path);
                    fs::rename(&info.deleted_path, &info.path)?;
                }
                _ => println!("Invalid number."),
            }
        }
    }

    Ok(())
}

M src/ops.rs => src/ops.rs +5 -8
@@ 9,9 9,6 @@ use crate::trashinfo::TrashInfo;

pub fn empty(dry: bool, days: Option<u32>) -> Result<(), Error> {
    let home_trash = TrashDir::get_home_trash();
    let files_dir = home_trash.files_dir()?;
    let info_dir = home_trash.info_dir()?;

    let cutoff = if let Some(days) = days {
        Local::now() - Duration::days(days.into())
    } else {


@@ 20,11 17,8 @@ pub fn empty(dry: bool, days: Option<u32>) -> Result<(), Error> {
    for file in home_trash.iter()? {
        let file = file?;

        let mut ignore = false;
        // ignore files that were deleted after the cutoff (younger)
        if file.deletion_date > cutoff {
            ignore = true;
        }
        let ignore = file.deletion_date > cutoff;

        if !ignore {
            if dry {


@@ 70,7 64,10 @@ pub fn put(path: impl AsRef<Path>, recursive: bool) -> Result<(), Error> {
        trash_info.write(&trash_info_file)?;
    }

    fs::rename(path, trash_file_path)?;
    let result = fs::rename(&path, &trash_file_path);
    if result.is_err() {
        fs::copy(&path, &trash_file_path)?;
    }

    Ok(())
}

M src/trashdir.rs => src/trashdir.rs +3 -1
@@ 69,7 69,9 @@ impl Iterator for TrashDirIter {
        let deleted_path = if !name.ends_with(".trashinfo") {
            return self.next();
        } else {
            self.0.join("files").join(name.trim_right_matches(".trashinfo"))
            self.0
                .join("files")
                .join(name.trim_end_matches(".trashinfo"))
        };
        Some(TrashInfo::from_files(entry.path(), deleted_path).map_err(Error::from))
    }

M src/trashinfo.rs => src/trashinfo.rs +4 -4
@@ 89,11 89,11 @@ impl TrashInfo {
    }

    pub fn write(&self, mut out: impl Write) -> Result<(), io::Error> {
        out.write(b"[Trash Info]\n")?;
        write!(out, "Path={}\n", self.path.to_str().unwrap())?;
        write!(
        writeln!(out, "[Trash Info]")?;
        writeln!(out, "Path={}", self.path.to_str().unwrap())?;
        writeln!(
            out,
            "DeletionDate={}\n",
            "DeletionDate={}",
            self.deletion_date.format(DATE_FORMAT)
        )?;
        Ok(())