mirror of
https://github.com/sreedevk/deduplicator.git
synced 2026-09-15 09:13:50 +00:00
added nocache option
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use anyhow::Result;
|
||||
use crate::cli::App;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct File {
|
||||
@@ -6,6 +7,18 @@ pub struct File {
|
||||
pub hash: String,
|
||||
}
|
||||
|
||||
pub fn get_connection(args: &App) -> Result<sqlite::Connection, sqlite::Error> {
|
||||
let connection_url = match args.nocache {
|
||||
false => "/tmp/deduplicator.db",
|
||||
true => ":memory:"
|
||||
};
|
||||
|
||||
sqlite::open(connection_url).and_then(|conn| {
|
||||
setup(&conn).ok();
|
||||
Ok(conn)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn setup(connection: &sqlite::Connection) -> Result<()> {
|
||||
let query = "CREATE TABLE files (file_identifier STRING, hash STRING)";
|
||||
connection.execute(query).ok();
|
||||
@@ -33,7 +46,7 @@ pub fn indexed_paths(connection: &sqlite::Connection) -> Result<Vec<File>> {
|
||||
.map(|row_result| row_result.unwrap())
|
||||
.map(|row| {
|
||||
let path = row.read::<&str, _>("file_identifier").to_string();
|
||||
let hash = row.read::<&str, _>("hash").to_string();
|
||||
let hash = row.read::<i64, _>("hash").to_string();
|
||||
File { path, hash }
|
||||
})
|
||||
.collect();
|
||||
@@ -60,7 +73,7 @@ pub fn duplicate_hashes(connection: &sqlite::Connection, path: &String) -> Resul
|
||||
.map(|row_result| row_result.unwrap())
|
||||
.map(|row| {
|
||||
let path = row.read::<&str, _>("file_identifier").to_string();
|
||||
let hash = row.read::<&str, _>("hash").to_string();
|
||||
let hash = row.read::<i64, _>("hash").to_string();
|
||||
File { path, hash }
|
||||
})
|
||||
.collect();
|
||||
|
||||
Reference in New Issue
Block a user