Projects STRLCPY deduplicator Commits 85acbded
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    src/app/event_handler.rs
    1 1  use std::time::Duration;
    2 2   
     3 +use anyhow::Result;
    3 4  use crossterm::event::{self, KeyCode, KeyEvent};
    4  -use anyhow::Result;
     5 + 
    5 6  use super::events;
    6 7   
    7 8  pub struct EventHandler;
    skipped 13 lines
    21 22   fn handle_keypress(keyevent: KeyEvent) -> Result<events::Event> {
    22 23   match keyevent.code {
    23 24   KeyCode::Char('q') => Ok(events::Event::Exit),
    24  - _ => Ok(events::Event::Noop)
     25 + _ => Ok(events::Event::Noop),
    25 26   }
    26 27   }
    27 28  }
    28 29   
    29  - 
  • ■ ■ ■ ■
    src/app/events.rs
    1 1  pub enum Event {
    2 2   Exit,
    3  - Noop
     3 + Noop,
    4 4  }
    5 5   
  • ■ ■ ■ ■ ■ ■
    src/app/mod.rs
    1 1  mod event_handler;
    2 2  mod events;
    3  -mod ui;
    4 3  mod formatter;
     4 +mod ui;
    5 5   
    6  -use crate::database;
    7  -use crate::output;
    8  -use crate::params::Params;
    9  -use crate::scanner;
     6 +use std::{io, thread, time::Duration};
     7 + 
    10 8  use anyhow::{anyhow, Result};
    11 9  use crossterm::{event, execute, terminal};
    12 10  use event_handler::EventHandler;
    13  -use std::io;
    14  -use std::thread;
    15  -use std::time::Duration;
    16 11  use tui::{
    17 12   backend::CrosstermBackend,
    18 13   widgets::{Block, Borders, Widget},
    skipped 1 lines
    20 15  };
    21 16  use ui::Ui;
    22 17   
     18 +use crate::database;
     19 +use crate::output;
     20 +use crate::params::Params;
     21 +use crate::scanner;
     22 + 
    23 23  pub struct App;
    24 24   
    25 25  impl App {
    26 26   pub fn init(app_args: &Params) -> Result<()> {
    27 27   // let mut term = Self::init_terminal()?;
    28 28   
    29  - let connection = database::get_connection(&app_args)?;
    30  - let duplicates = scanner::duplicates(&app_args, &connection)?;
     29 + let connection = database::get_connection(app_args)?;
     30 + let duplicates = scanner::duplicates(app_args, &connection)?;
    31 31   
    32 32   // Self::init_render_loop(&mut term)?;
    33 33   // Self::cleanup(&mut term)?;
    34 34   
    35  - output::print(duplicates, &app_args); /* TODO: APP TUI INIT FUNCTION */
     35 + output::print(duplicates, app_args); /* TODO: APP TUI INIT FUNCTION */
    36 36   Ok(())
    37 37   }
    38 38   
    skipped 17 lines
    56 56   }
    57 57   
    58 58   fn init_render_loop(term: &mut Terminal<CrosstermBackend<io::Stdout>>) -> Result<()> {
     59 + // this could be simplified with a `while Self::render_cycle(term).is_ok() {}` in the current state, but maybe
     60 + // it's good to keep it to handle errors in the future
    59 61   loop {
    60 62   match Self::render_cycle(term) {
    61 63   Ok(_) => continue,
    skipped 20 lines
  • ■ ■ ■ ■ ■
    src/app/ui.rs
     1 +use std::io;
     2 + 
    1 3  use anyhow::Result;
    2  -use std::io;
    3 4  use tui::{
    4 5   backend::{Backend, CrosstermBackend},
    5 6   layout::{Constraint, Direction, Layout, Rect},
    skipped 49 lines
  • ■ ■ ■ ■ ■ ■
    src/database.rs
    1  -use crate::params::Params;
    2  -use anyhow::Result;
    3 1  use std::env::temp_dir;
     2 + 
     3 +use anyhow::Result;
     4 + 
     5 +use crate::params::Params;
    4 6   
    5 7  #[derive(Debug, Clone)]
    6 8  pub struct File {
    skipped 14 lines
    21 23  pub fn get_connection(args: &Params) -> Result<sqlite::Connection, sqlite::Error> {
    22 24   sqlite::open(db_connection_url(args)).and_then(|conn| {
    23 25   setup(&conn).ok();
    24  - Ok(conn)
     26 + conn
    25 27   })
    26 28  }
    27 29   
    skipped 8 lines
    36 38   "INSERT INTO files (file_identifier, hash) VALUES (\"{}\", \"{}\")",
    37 39   file.path, file.hash
    38 40   );
    39  - let result = connection.execute(query)?;
    40  - 
    41  - Ok(result)
     41 + connection.execute(query)?;
     42 + Ok(())
    42 43  }
    43 44   
    44 45  pub fn indexed_paths(connection: &sqlite::Connection) -> Result<Vec<File>> {
    45  - let query = format!("SELECT * FROM files");
     46 + let query = "SELECT * FROM files";
    46 47   
    47 48   let result: Vec<File> = connection
    48 49   .prepare(query)?
    49 50   .into_iter()
    50  - .map(|row_result| row_result.unwrap())
     51 + .filter_map(|row_result| row_result.ok())
    51 52   .map(|row| {
    52 53   let path = row.read::<&str, _>("file_identifier").to_string();
    53 54   let hash = row.read::<i64, _>("hash").to_string();
    skipped 4 lines
    58 59   Ok(result)
    59 60  }
    60 61   
    61  -pub fn duplicate_hashes(connection: &sqlite::Connection, path: &String) -> Result<Vec<File>> {
     62 +pub fn duplicate_hashes(connection: &sqlite::Connection, path: &str) -> Result<Vec<File>> {
    62 63   let query = format!(
    63 64   "
    64 65   SELECT a.* FROM files a
    skipped 11 lines
    76 77   let result: Vec<File> = connection
    77 78   .prepare(query)?
    78 79   .into_iter()
    79  - .map(|row_result| row_result.unwrap())
     80 + .filter_map(|row_result| row_result.ok())
    80 81   .map(|row| {
    81 82   let path = row.read::<&str, _>("file_identifier").to_string();
    82 83   let hash = row.read::<i64, _>("hash").to_string();
    skipped 7 lines
  • ■ ■ ■ ■ ■ ■
    src/main.rs
    1  -mod params;
     1 +#![allow(unused)] // TODO: remove this once TUI is implemented
     2 +mod app;
    2 3  mod database;
    3 4  mod output;
     5 +mod params;
    4 6  mod scanner;
    5  -mod app;
    6 7   
    7 8  use anyhow::Result;
     9 +use app::App;
    8 10  use clap::Parser;
    9  -use app::App;
    10 11   
    11 12  #[tokio::main]
    12 13  async fn main() -> Result<()> {
    skipped 3 lines
  • ■ ■ ■ ■ ■ ■
    src/params.rs
    1  -use std::path::PathBuf;
     1 +use std::{fs, path::PathBuf};
     2 + 
     3 +use anyhow::{anyhow, Result};
    2 4  use clap::Parser;
    3  -use anyhow::Result;
    4  -use std::fs;
    5 5   
    6 6  #[derive(Parser, Debug)]
    7 7  #[command(author, version, about, long_about = None)]
    skipped 11 lines
    19 19   
    20 20  impl Params {
    21 21   pub fn get_directory(&self) -> Result<String> {
    22  - let dir_string: String = self
     22 + let dir_pathbuf: PathBuf = self
    23 23   .dir
    24 24   .clone()
    25 25   .unwrap_or(std::env::current_dir()?)
    26 26   .as_os_str()
    27  - .to_str()
    28  - .unwrap()
    29  - .to_string();
     27 + .into();
    30 28   
    31  - let dir_pathbuf = PathBuf::from(&dir_string);
    32  - let dir = fs::canonicalize(&dir_pathbuf)?
     29 + let dir = fs::canonicalize(dir_pathbuf)?
    33 30   .as_os_str()
    34 31   .to_str()
    35  - .unwrap()
     32 + .ok_or_else(|| anyhow!("Invalid directory"))?
    36 33   .to_string();
    37 34   
    38 35   Ok(dir)
    skipped 3 lines
Please wait...
Page is in error, reload to recover