improvenments to delete function; need to handle filled dir still

This commit is contained in:
nova
2025-07-14 01:04:36 +02:00
parent b9c254a0fe
commit 2105bb4fe5

View File

@ -1,6 +1,7 @@
#include <curses.h>
#include <pthread.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <signal.h>
@ -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);