improvenments to delete function; need to handle filled dir still
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -394,17 +395,17 @@ void delete(){
|
|||||||
char ch = wgetch(win_b);
|
char ch = wgetch(win_b);
|
||||||
|
|
||||||
if (ch == 'y' || ch == 'Y') {
|
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 */
|
/* 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) {
|
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++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
||||||
free(cmd);
|
error = remove(mid_content[i].file_name);
|
||||||
cmd = concat("rm -rf ./\"", mid_content[i].file_name);
|
if (error != 0) {
|
||||||
cmd = concat(cmd, "\"");
|
mvaddstr(terminal_height-j, 0, "could not delete: " );
|
||||||
if (system(cmd) == -1) {
|
mvaddstr(terminal_height-j, strlen("could not delete: "), mid_content[i].file_name);
|
||||||
FAIL("delete", "rm -rf or creating subcommand failed");
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -412,18 +413,18 @@ void delete(){
|
|||||||
btm_buffer = concat("deleted: ", file_str);
|
btm_buffer = concat("deleted: ", file_str);
|
||||||
} else {
|
} else {
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
btm_buffer = concat("deleted: \"", file_current->file_name);
|
error = remove(file_current->file_name);
|
||||||
btm_buffer = concat(btm_buffer, "\"");
|
if (error != 0) {
|
||||||
free(cmd);
|
mvaddstr(terminal_height-2, 0, "could not delete: " );
|
||||||
cmd = concat("rm -rf ./\"", file_current->file_name);
|
mvaddstr(terminal_height-2, strlen("could not delete: "), mid_content[i].file_name);
|
||||||
cmd = concat(cmd, "\"");
|
btm_buffer = " ";
|
||||||
if (system(cmd) == -1) {
|
} else {
|
||||||
FAIL("delete", "rm -rf or creating subcommand failed");
|
btm_buffer = concat("deleted: \"", file_current->file_name);
|
||||||
}
|
btm_buffer = concat(btm_buffer, "\"");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/*system(cmd);*/
|
/*system(cmd);*/
|
||||||
free(cmd);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
|
Reference in New Issue
Block a user