mirror of
https://github.com/sreedevk/deduplicator.git
synced 2026-09-01 04:55:33 +00:00
bug fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use anyhow::Result;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct File {
|
||||
pub path: String,
|
||||
pub hash: String,
|
||||
@@ -41,7 +41,7 @@ pub fn indexed_paths(connection: &sqlite::Connection) -> Result<Vec<File>> {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn duplicate_hashes(connection: &sqlite::Connection) -> Result<Vec<File>> {
|
||||
pub fn duplicate_hashes(connection: &sqlite::Connection, path: &String) -> Result<Vec<File>> {
|
||||
let query = format!(
|
||||
"
|
||||
SELECT a.* FROM files a
|
||||
@@ -50,8 +50,9 @@ pub fn duplicate_hashes(connection: &sqlite::Connection) -> Result<Vec<File>> {
|
||||
GROUP BY hash
|
||||
HAVING count(*) > 1 ) b
|
||||
ON a.hash = b.hash
|
||||
WHERE a.file_identifier LIKE \"{}%\"
|
||||
ORDER BY a.file_identifier
|
||||
"
|
||||
", path
|
||||
);
|
||||
let result: Vec<File> = connection
|
||||
.prepare(query)?
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use crate::database::File;
|
||||
use itertools::Itertools;
|
||||
use colored::Colorize;
|
||||
use std::fs;
|
||||
use chrono::offset::Utc;
|
||||
use chrono::DateTime;
|
||||
use colored::Colorize;
|
||||
use humansize::{format_size, DECIMAL};
|
||||
use std::{collections::HashMap, fs};
|
||||
|
||||
fn format_path(path: &String) -> String {
|
||||
let stringlen = path.len();
|
||||
@@ -36,22 +35,25 @@ pub fn print(duplicates: Vec<File>) {
|
||||
);
|
||||
print_divider();
|
||||
|
||||
duplicates
|
||||
.into_iter()
|
||||
.group_by(|record| record.hash.clone())
|
||||
.into_iter()
|
||||
.for_each(|(_, group)| {
|
||||
group
|
||||
.into_iter()
|
||||
.for_each(|file| {
|
||||
println!(
|
||||
"| {0: <16} | {1: <35} | {2: <16} | {3: <32} |",
|
||||
&file.hash[0..16].red(),
|
||||
format_path(&file.path).yellow(),
|
||||
file_size(&file.path).blue(),
|
||||
modified_time(&file.path).blue()
|
||||
);
|
||||
});
|
||||
print_divider();
|
||||
let mut dup_index: HashMap<String, Vec<File>> = HashMap::new();
|
||||
|
||||
duplicates.into_iter().for_each(|file| {
|
||||
dup_index
|
||||
.entry(file.hash.clone())
|
||||
.and_modify(|value| value.push(file.clone()))
|
||||
.or_insert(vec![file]);
|
||||
});
|
||||
|
||||
dup_index.into_iter().for_each(|(_, group)| {
|
||||
group.into_iter().for_each(|file| {
|
||||
println!(
|
||||
"| {0: <16} | {1: <35} | {2: <16} | {3: <32} |",
|
||||
&file.hash[0..16].red(),
|
||||
format_path(&file.path).yellow(),
|
||||
file_size(&file.path).blue(),
|
||||
modified_time(&file.path).blue()
|
||||
);
|
||||
});
|
||||
print_divider();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::database;
|
||||
use crate::{cli::App, database::File};
|
||||
use anyhow::Result;
|
||||
@@ -7,11 +5,14 @@ use glob::glob;
|
||||
use itertools::Itertools;
|
||||
use rayon::prelude::*;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn duplicates(app_opts: App, connection: &sqlite::Connection) -> Result<Vec<File>> {
|
||||
let scan_results = scan(app_opts, connection)?;
|
||||
let scan_results = scan(&app_opts, connection)?;
|
||||
let base_path = get_directory(&app_opts)?;
|
||||
|
||||
index_files(scan_results, connection);
|
||||
database::duplicate_hashes(connection)
|
||||
database::duplicate_hashes(connection, &base_path)
|
||||
}
|
||||
|
||||
fn get_directory(opts: &App) -> Result<String> {
|
||||
@@ -55,8 +56,8 @@ fn is_indexed_file(path: &String, indexed: &Vec<File>) -> bool {
|
||||
.contains(path)
|
||||
}
|
||||
|
||||
fn scan(app_opts: App, connection: &sqlite::Connection) -> Result<Vec<String>> {
|
||||
let directory = get_directory(&app_opts)?;
|
||||
fn scan(app_opts: &App, connection: &sqlite::Connection) -> Result<Vec<String>> {
|
||||
let directory = get_directory(app_opts)?;
|
||||
let glob_patterns: Vec<PathBuf> = get_glob_patterns(&app_opts, &directory);
|
||||
let indexed_paths = database::indexed_paths(connection)?;
|
||||
let files: Vec<String> = glob_patterns
|
||||
|
||||
Reference in New Issue
Block a user