mirror of
https://github.com/sreedevk/deduplicator.git
synced 2026-09-07 02:24:24 +00:00
replace path String in File type with PathBuf
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub path: String,
|
pub path: PathBuf,
|
||||||
pub size: Option<u64>,
|
pub size: Option<u64>,
|
||||||
pub hash: Option<String>,
|
pub hash: Option<String>,
|
||||||
}
|
}
|
||||||
@@ -11,8 +12,8 @@ pub struct File {
|
|||||||
pub fn delete_files(files: Vec<File>) -> Result<()> {
|
pub fn delete_files(files: Vec<File>) -> Result<()> {
|
||||||
files.into_iter().for_each(|file| {
|
files.into_iter().for_each(|file| {
|
||||||
match std::fs::remove_file(file.path.clone()) {
|
match std::fs::remove_file(file.path.clone()) {
|
||||||
Ok(_) => println!("{}: {}", "DELETED".green(), file.path),
|
Ok(_) => println!("{}: {}", "DELETED".green(), file.path.display()),
|
||||||
Err(_) => println!("{}: {}", "FAILED".red(), file.path)
|
Err(_) => println!("{}: {}", "FAILED".red(), file.path.display())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,14 @@ use indicatif::{ProgressBar, ProgressIterator, ProgressStyle};
|
|||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use prettytable::{format, row, Table};
|
use prettytable::{format, row, Table};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::path::Path;
|
||||||
use std::{fs, io};
|
use std::{fs, io};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
fn format_path(path: &str, opts: &Params) -> Result<String> {
|
fn format_path(path: &Path, opts: &Params) -> Result<String> {
|
||||||
let display_path = path.replace(opts.get_directory()?.to_string_lossy().as_ref(), "");
|
let display_path = path
|
||||||
|
.to_string_lossy()
|
||||||
|
.replace(opts.get_directory()?.to_string_lossy().as_ref(), "");
|
||||||
let display_range = if display_path.chars().count() > 32 {
|
let display_range = if display_path.chars().count() > 32 {
|
||||||
display_path
|
display_path
|
||||||
.graphemes(true)
|
.graphemes(true)
|
||||||
@@ -34,7 +37,7 @@ fn file_size(file: &File) -> Result<String> {
|
|||||||
Ok(format!("{:>12}", bytesize::ByteSize::b(file.size.unwrap())))
|
Ok(format!("{:>12}", bytesize::ByteSize::b(file.size.unwrap())))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modified_time(path: &String) -> Result<String> {
|
fn modified_time(path: &Path) -> Result<String> {
|
||||||
let mdata = fs::metadata(path)?;
|
let mdata = fs::metadata(path)?;
|
||||||
let modified_time: DateTime<Utc> = mdata.modified()?.into();
|
let modified_time: DateTime<Utc> = mdata.modified()?.into();
|
||||||
|
|
||||||
@@ -100,7 +103,7 @@ fn process_group_action(duplicates: &Vec<File>, dup_index: usize, dup_size: usiz
|
|||||||
.clone()
|
.clone()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.for_each(|(index, file)| {
|
.for_each(|(index, file)| {
|
||||||
println!("{}: {}", index.to_string().blue(), file.path);
|
println!("{}: {}", index.to_string().blue(), file.path.display());
|
||||||
});
|
});
|
||||||
|
|
||||||
match scan_group_confirmation().unwrap() {
|
match scan_group_confirmation().unwrap() {
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ use memmap2::Mmap;
|
|||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::hash::Hasher;
|
use std::hash::Hasher;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::{fs, path::PathBuf};
|
use std::{
|
||||||
|
fs,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
enum IndexCritera {
|
enum IndexCritera {
|
||||||
@@ -57,7 +60,6 @@ fn scan(app_opts: &Params) -> Result<Vec<File>> {
|
|||||||
.progress_with_style(ProgressStyle::with_template(
|
.progress_with_style(ProgressStyle::with_template(
|
||||||
"{spinner:.green} [processing mapped paths] [{wide_bar:.cyan/blue}] {pos}/{len} files",
|
"{spinner:.green} [processing mapped paths] [{wide_bar:.cyan/blue}] {pos}/{len} files",
|
||||||
)?)
|
)?)
|
||||||
.map(|fpath| fpath.display().to_string())
|
|
||||||
.map(|fpath| File {
|
.map(|fpath| File {
|
||||||
path: fpath.clone(),
|
path: fpath.clone(),
|
||||||
hash: None,
|
hash: None,
|
||||||
@@ -110,7 +112,7 @@ fn index_files(
|
|||||||
Ok(store)
|
Ok(store)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn incremental_hashing(filepath: &str) -> Result<String> {
|
fn incremental_hashing(filepath: &Path) -> Result<String> {
|
||||||
let file = fs::File::open(filepath)?;
|
let file = fs::File::open(filepath)?;
|
||||||
let fmap = unsafe { Mmap::map(&file)? };
|
let fmap = unsafe { Mmap::map(&file)? };
|
||||||
let mut inchasher = fxhash::FxHasher::default();
|
let mut inchasher = fxhash::FxHasher::default();
|
||||||
@@ -121,12 +123,12 @@ fn incremental_hashing(filepath: &str) -> Result<String> {
|
|||||||
Ok(format!("{}", inchasher.finish()))
|
Ok(format!("{}", inchasher.finish()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn standard_hashing(filepath: &str) -> Result<String> {
|
fn standard_hashing(filepath: &Path) -> Result<String> {
|
||||||
let file = fs::read(filepath)?;
|
let file = fs::read(filepath)?;
|
||||||
Ok(hasher(&*file).to_string())
|
Ok(hasher(&*file).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_file(filepath: &str) -> Result<String> {
|
fn hash_file(filepath: &Path) -> Result<String> {
|
||||||
let filemeta = fs::metadata(filepath)?;
|
let filemeta = fs::metadata(filepath)?;
|
||||||
|
|
||||||
// NOTE: USE INCREMENTAL HASHING ONLY FOR FILES > 100MB
|
// NOTE: USE INCREMENTAL HASHING ONLY FOR FILES > 100MB
|
||||||
|
|||||||
Reference in New Issue
Block a user