mirror of
https://github.com/sreedevk/deduplicator.git
synced 2026-08-31 20:45:34 +00:00
restructuring
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use anyhow::Result;
|
||||
use crate::params::App;
|
||||
use crate::params::Params;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct File {
|
||||
@@ -7,7 +7,7 @@ pub struct File {
|
||||
pub hash: String,
|
||||
}
|
||||
|
||||
pub fn get_connection(args: &App) -> Result<sqlite::Connection, sqlite::Error> {
|
||||
pub fn get_connection(args: &Params) -> Result<sqlite::Connection, sqlite::Error> {
|
||||
let connection_url = match args.nocache {
|
||||
false => "/tmp/deduplicator.db",
|
||||
true => ":memory:"
|
||||
|
||||
@@ -8,7 +8,7 @@ use clap::Parser;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let app_args = params::App::parse();
|
||||
let app_args = params::Params::parse();
|
||||
let connection = database::get_connection(&app_args)?;
|
||||
let duplicates = scanner::duplicates(&app_args, &connection)?;
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ use chrono::DateTime;
|
||||
use colored::Colorize;
|
||||
use humansize::{format_size, DECIMAL};
|
||||
use std::{collections::HashMap, fs};
|
||||
use crate::params::App;
|
||||
use crate::params::Params;
|
||||
|
||||
fn format_path(path: &String, opts: &App) -> String {
|
||||
fn format_path(path: &String, opts: &Params) -> String {
|
||||
format!("...{}", path.replace(&opts.get_directory().unwrap(), ""))
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ fn print_divider() {
|
||||
println!("-------------------+-------------------------------------+------------------+----------------------------------+");
|
||||
}
|
||||
|
||||
pub fn print(duplicates: Vec<File>, opts: &App) {
|
||||
pub fn print(duplicates: Vec<File>, opts: &Params) {
|
||||
print_divider();
|
||||
println!(
|
||||
"| {0: <16} | {1: <35} | {2: <16} | {3: <32} |",
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::fs;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct App {
|
||||
pub struct Params {
|
||||
/// Filetypes to deduplicate (default = all)
|
||||
#[arg(short, long)]
|
||||
pub types: Option<String>,
|
||||
@@ -17,7 +17,7 @@ pub struct App {
|
||||
pub nocache: bool,
|
||||
}
|
||||
|
||||
impl App {
|
||||
impl Params {
|
||||
pub fn get_directory(&self) -> Result<String> {
|
||||
let dir_string: String = self
|
||||
.dir
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::database;
|
||||
use crate::{params::App, database::File};
|
||||
use crate::{params::Params, database::File};
|
||||
use anyhow::Result;
|
||||
use glob::glob;
|
||||
use itertools::Itertools;
|
||||
@@ -8,7 +8,7 @@ use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use fxhash::hash32 as hasher;
|
||||
|
||||
pub fn duplicates(app_opts: &App, connection: &sqlite::Connection) -> Result<Vec<File>> {
|
||||
pub fn duplicates(app_opts: &Params, connection: &sqlite::Connection) -> Result<Vec<File>> {
|
||||
let scan_results = scan(app_opts, connection)?;
|
||||
let base_path = app_opts.get_directory()?;
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn duplicates(app_opts: &App, connection: &sqlite::Connection) -> Result<Vec
|
||||
database::duplicate_hashes(connection, &base_path)
|
||||
}
|
||||
|
||||
fn get_glob_patterns(opts: &App, directory: &String) -> Vec<PathBuf> {
|
||||
fn get_glob_patterns(opts: &Params, directory: &String) -> Vec<PathBuf> {
|
||||
opts.types
|
||||
.clone()
|
||||
.unwrap_or(String::from("*"))
|
||||
@@ -37,7 +37,7 @@ fn is_indexed_file(path: &String, indexed: &Vec<File>) -> bool {
|
||||
.contains(path)
|
||||
}
|
||||
|
||||
fn scan(app_opts: &App, connection: &sqlite::Connection) -> Result<Vec<String>> {
|
||||
fn scan(app_opts: &Params, connection: &sqlite::Connection) -> Result<Vec<String>> {
|
||||
let directory = app_opts.get_directory()?;
|
||||
let glob_patterns: Vec<PathBuf> = get_glob_patterns(&app_opts, &directory);
|
||||
let indexed_paths = database::indexed_paths(connection)?;
|
||||
|
||||
Reference in New Issue
Block a user