From 2105bb4fe50136e46b5a49f483569c7621419a85 Mon Sep 17 00:00:00 2001 From: nova Date: Mon, 14 Jul 2025 01:04:36 +0200 Subject: [PATCH] improvenments to delete function; need to handle filled dir still --- interactions.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/interactions.c b/interactions.c index d20f558..4af8ed8 100644 --- a/interactions.c +++ b/interactions.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -394,17 +395,17 @@ void delete(){ char ch = wgetch(win_b); if (ch == 'y' || ch == 'Y') { - char *cmd = malloc(sizeof(char)); /* TODO(2025-06-30T02:27:06) IMPORTANT: this really fucks up when the file has a quotation mark in its name */ + int error; if (hits) { - /* the second loop is used to add "./", wich is not being printed" */ + int j = 2; for (i = 0; i < mid_file_count; i++) { if (mid_content[i].status & FILE_STATUS_SELECTED) { - free(cmd); - cmd = concat("rm -rf ./\"", mid_content[i].file_name); - cmd = concat(cmd, "\""); - if (system(cmd) == -1) { - FAIL("delete", "rm -rf or creating subcommand failed"); + error = remove(mid_content[i].file_name); + if (error != 0) { + mvaddstr(terminal_height-j, 0, "could not delete: " ); + mvaddstr(terminal_height-j, strlen("could not delete: "), mid_content[i].file_name); + j++; } } } @@ -412,18 +413,18 @@ void delete(){ btm_buffer = concat("deleted: ", file_str); } else { free(btm_buffer); - btm_buffer = concat("deleted: \"", file_current->file_name); - btm_buffer = concat(btm_buffer, "\""); - free(cmd); - cmd = concat("rm -rf ./\"", file_current->file_name); - cmd = concat(cmd, "\""); - if (system(cmd) == -1) { - FAIL("delete", "rm -rf or creating subcommand failed"); - } + error = remove(file_current->file_name); + if (error != 0) { + mvaddstr(terminal_height-2, 0, "could not delete: " ); + mvaddstr(terminal_height-2, strlen("could not delete: "), mid_content[i].file_name); + btm_buffer = " "; + } else { + btm_buffer = concat("deleted: \"", file_current->file_name); + btm_buffer = concat(btm_buffer, "\""); + } } /*system(cmd);*/ - free(cmd); } else { free(btm_buffer);