Skip to content

Commit

Permalink
Merge pull request #30 from AmineZouitine/compress
Browse files Browse the repository at this point in the history
fix flush command
  • Loading branch information
AmineZouitine authored Nov 9, 2022
2 parents 17c53b1 + 1580caa commit 10257cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/input_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 23 additions & 3 deletions src/trash_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -103,14 +107,26 @@ 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);
data_manager::delete_trash_item_by_id(connection, is_test, *trash_item_id);
});
}

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!(
"{}/{}",
Expand All @@ -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);
Expand Down

0 comments on commit 10257cb

Please sign in to comment.