From 1580caa9d4fafbbbbe44a1c66b909fb3b442fa34 Mon Sep 17 00:00:00 2001 From: AmineZouitine Date: Wed, 9 Nov 2022 10:53:04 +0100 Subject: [PATCH] fix flush command --- src/input_manager.rs | 4 ++-- src/main.rs | 2 +- src/trash_manager.rs | 26 +++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/input_manager.rs b/src/input_manager.rs index 383d2d6..a9deb45 100644 --- a/src/input_manager.rs +++ b/src/input_manager.rs @@ -82,12 +82,12 @@ pub fn start_display(connection: &Connection, is_test: bool) { write!(stdout_display, "{}", termion::cursor::Show).unwrap(); write!(stdout_display, "{}", termion::clear::All).unwrap(); - trash_manager::remove_all_elements( + trash_manager::remove_all_elements_selected( connection, is_test, &display_informations.selected_trash_items.delete, ); - trash_manager::restore_all_elements( + trash_manager::restore_all_elements_selected( connection, is_test, &display_informations.selected_trash_items.restore, diff --git a/src/main.rs b/src/main.rs index a2eed94..3c672a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ fn main() { "flush".green().bold() ); if display_manager::get_user_validation(&message) { - data_manager::delete_all_trash_item(&connection, IS_TEST); + trash_manager::remove_all_elements(&connection, IS_TEST); } } else if arguments_manager.is_trash_info { trash_manager::display_trash_information(&connection, IS_TEST); diff --git a/src/trash_manager.rs b/src/trash_manager.rs index d4d9542..4f06f3e 100644 --- a/src/trash_manager.rs +++ b/src/trash_manager.rs @@ -5,12 +5,12 @@ use crate::{ config::Config, data_manager, structure_manager::get_trash_directory_path, trash_item::TrashItem, }; - use chrono; use colored::Colorize; use fs_extra::dir::{self, get_size}; use rusqlite::Connection; use sha256; +use std::process::Command; use std::fs; use std::io::{stdout, Write}; @@ -40,6 +40,10 @@ pub fn add_element_to_trash( let element_is_directory = Path::new(&element_path).is_dir(); if config.compression { + Command::new("zip") + .arg("-qr") + .arg(&new_name) + .arg(&element_path); // TODO } else { fs::rename(&element_path, &new_name).unwrap(); @@ -103,7 +107,11 @@ pub fn add_all_elements_to_trash( } } -pub fn remove_all_elements(connection: &Connection, is_test: bool, trash_items_ids: &[i32]) { +pub fn remove_all_elements_selected( + connection: &Connection, + is_test: bool, + trash_items_ids: &[i32], +) { trash_items_ids.iter().for_each(|trash_item_id| { let trash_item = data_manager::find_trash_item_by_id(connection, is_test, *trash_item_id); remove_element(&trash_item, is_test); @@ -111,6 +119,14 @@ pub fn remove_all_elements(connection: &Connection, is_test: bool, trash_items_i }); } +pub fn remove_all_elements(connection: &Connection, is_test: bool) { + let trash_items = data_manager::find_all_trash_items(connection, is_test); + trash_items.iter().for_each(|trash_item| { + remove_element(trash_item, is_test); + }); + data_manager::delete_all_trash_item(connection, is_test); +} + fn remove_element(trash_item: &TrashItem, is_test: bool) { let element_path = format!( "{}/{}", @@ -130,7 +146,11 @@ fn remove_element(trash_item: &TrashItem, is_test: bool) { ); } -pub fn restore_all_elements(connection: &Connection, is_test: bool, trash_items_ids: &[i32]) { +pub fn restore_all_elements_selected( + connection: &Connection, + is_test: bool, + trash_items_ids: &[i32], +) { trash_items_ids.iter().for_each(|trash_item_id| { let trash_item = data_manager::find_trash_item_by_id(connection, is_test, *trash_item_id); restore_element(&trash_item, is_test);