better chdir handling
This commit is contained in:
47
dir.c
47
dir.c
@@ -308,37 +308,60 @@ void dir_changed(){
|
|||||||
}
|
}
|
||||||
if(strcmp(current_linked_dir->path, path) == 0) {
|
if(strcmp(current_linked_dir->path, path) == 0) {
|
||||||
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/*this path should only ever happen on changing the path for the first time
|
/**/
|
||||||
*at least i hope so*/
|
|
||||||
current_linked_dir->next = malloc(sizeof(linked_dir));
|
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||||
current_linked_dir->next->path = malloc(strlen(global_path)+1);
|
current_linked_dir->next->path = malloc(strlen(global_path)+1);
|
||||||
memcpy(current_linked_dir->next->path, global_path, strlen(global_path)+1);
|
memcpy(current_linked_dir->next->path, global_path, strlen(global_path)+1);
|
||||||
current_linked_dir->next->next = NULL;
|
current_linked_dir->next->next = NULL;
|
||||||
current_linked_dir->next->index = 0;
|
current_linked_dir->next->index = 0;
|
||||||
|
|
||||||
|
mid_dir.current_file = mid_dir.file_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
void change_dir(){
|
void change_dir(char *new_path){
|
||||||
|
|
||||||
|
char *old_path = getcwd(NULL, 0);
|
||||||
current_linked_dir = list_beginning;
|
current_linked_dir = list_beginning;
|
||||||
while (current_linked_dir->next != NULL) {
|
while (current_linked_dir->next != NULL) {
|
||||||
if(strcmp(current_linked_dir->path, global_path) == 0) {
|
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
current_linked_dir = current_linked_dir->next;
|
current_linked_dir = current_linked_dir->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(strcmp(current_linked_dir->path, global_path) == 0) {
|
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
||||||
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
|
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
|
||||||
} else {
|
|
||||||
current_linked_dir->next = malloc(sizeof(linked_dir));
|
|
||||||
current_linked_dir->next->path = malloc(strlen(global_path)+1);
|
|
||||||
memcpy(current_linked_dir->next->path, global_path, strlen(global_path)+1);
|
|
||||||
current_linked_dir->next->next = NULL;
|
|
||||||
current_linked_dir->next->index = mid_dir.current_file - mid_dir.file_list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chdir(new_path);
|
||||||
|
char *new_path_real = getcwd(NULL, 0);
|
||||||
|
|
||||||
|
current_linked_dir = list_beginning;
|
||||||
|
while (current_linked_dir->next != NULL) {
|
||||||
|
if(strcmp(current_linked_dir->path, new_path_real) == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
current_linked_dir = current_linked_dir->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(current_linked_dir->path, new_path_real) != 0) {
|
||||||
|
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||||
|
current_linked_dir = current_linked_dir->next;
|
||||||
|
current_linked_dir->path = malloc(strlen(new_path_real)+1);
|
||||||
|
memcpy(current_linked_dir->path, new_path_real, strlen(new_path_real)+1);
|
||||||
|
current_linked_dir->next = NULL;
|
||||||
|
current_linked_dir->index = 0;
|
||||||
|
/*TODO(2026-05-25T22:49:30)
|
||||||
|
*handle if new_path == "..", should this case be true, focus the index on which the old_path falls on*/
|
||||||
|
}
|
||||||
|
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||||
|
|
||||||
|
free(old_path);
|
||||||
|
free(new_path_real);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dir_init(){
|
void dir_init(){
|
||||||
|
|||||||
@@ -184,12 +184,7 @@ void move_up(unsigned long passes){
|
|||||||
void move_left(unsigned long passes){
|
void move_left(unsigned long passes){
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
for (i = 0; i < passes; i++) {
|
for (i = 0; i < passes; i++) {
|
||||||
change_dir();
|
change_dir("..");
|
||||||
if (chdir("..") != 0) {
|
|
||||||
/* TODO(2025-07-09T00:30:05) fix */
|
|
||||||
FAIL("move_left", "unhandled error of chdir");
|
|
||||||
}
|
|
||||||
dir_changed();
|
|
||||||
}
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
|
|
||||||
@@ -197,14 +192,8 @@ void move_left(unsigned long passes){
|
|||||||
void move_right(){
|
void move_right(){
|
||||||
|
|
||||||
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||||
change_dir();
|
change_dir(mid_dir.current_file->file_name);
|
||||||
if (chdir(mid_dir.current_file->file_name) != 0) {
|
|
||||||
/* TODO(2026-05-05T20:12:14) fix */
|
|
||||||
FAIL("move_right", "unhandled error of chdir");
|
|
||||||
}
|
|
||||||
dir_changed();
|
|
||||||
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
||||||
chdir(".");
|
|
||||||
char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file);
|
char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file);
|
||||||
if (system(cmd)) {
|
if (system(cmd)) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user