proper handling of empty dirs (hopefully)

This commit is contained in:
nova
2026-06-15 20:28:39 +02:00
parent 4def2c7cf0
commit c0299aef8c
4 changed files with 68 additions and 30 deletions
+45 -29
View File
@@ -85,6 +85,7 @@ void *thread_mid(){
} else { /* the hovered dir is empty */
mid_dir.current_file = NULL;
mid_dir.file_list = NULL;
}
unsigned long i;
@@ -95,11 +96,13 @@ void *thread_mid(){
}
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
}
if (mid_dir.current_file < mid_dir.file_list) {
mid_dir.current_file = mid_dir.file_list;
if (mid_dir.current_file != NULL) {
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
}
if (mid_dir.current_file < mid_dir.file_list) {
mid_dir.current_file = mid_dir.file_list;
}
}
pthread_mutex_unlock(&mutex_mid);
@@ -204,20 +207,26 @@ void *thread_rgt(){
pthread_mutex_lock(&mutex_mid);
char *file_name = malloc(strlen(mid_dir.current_file->file_name)+1);
file_name = memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
if (mid_dir.current_file != NULL) {
char *file_name = malloc(strlen(mid_dir.current_file->file_name)+1);
file_name = memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
rgt_dir.file_list = malloc(sizeof(file));
memcpy(rgt_dir.file_list, mid_dir.current_file, sizeof(file));
rgt_dir.file_list->file_name = file_name;
rgt_dir.current_file = rgt_dir.file_list;
rgt_dir.file_count = 1;
rgt_dir.file_list = malloc(sizeof(file));
memcpy(rgt_dir.file_list, mid_dir.current_file, sizeof(file));
rgt_dir.file_list->file_name = file_name;
rgt_dir.current_file = rgt_dir.file_list;
rgt_dir.file_count = 1;
} else {
rgt_dir.current_file = NULL;
rgt_dir.file_list = NULL;
rgt_dir.file_count = 0;
}
pthread_mutex_unlock(&mutex_mid);
if (rgt_dir.current_file->permissions & S_IRUSR) {
if (rgt_dir.current_file != NULL && rgt_dir.current_file->permissions & S_IRUSR) {
if (rgt_dir.current_file->file_type & FILE_TYPE_DIR) {
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
images_clear();
@@ -288,13 +297,18 @@ void *thread_top(){
pthread_mutex_lock(&mutex_mid);
top_buffer = malloc(strlen(global_path)+1 + strlen(mid_dir.current_file->file_name)+1);
memcpy(top_buffer, global_path, strlen(global_path));
memcpy(top_buffer + strlen(global_path) + 1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
if (mid_dir.current_file != NULL) {
top_buffer = malloc(strlen(global_path)+1 + strlen(mid_dir.current_file->file_name)+1);
memcpy(top_buffer, global_path, strlen(global_path));
memcpy(top_buffer + strlen(global_path) + 1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
top_buffer[strlen(global_path)] = '/';
top_width = strlen(top_buffer);
} else {
top_buffer = malloc(strlen(global_path)+1);
memcpy(top_buffer, global_path, strlen(global_path)+1);
}
pthread_mutex_unlock(&mutex_mid);
top_buffer[strlen(global_path)] = '/';
top_width = strlen(top_buffer);
/* rendering */
@@ -404,17 +418,19 @@ void *thread_btm(){
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
btm_buffer[0] = (S_ISLNK(mid_dir.current_file->permissions)) ? 'l':
(S_ISDIR(mid_dir.current_file->permissions) ? 'd': '-');
btm_buffer[1] = (mid_dir.current_file->permissions & S_IRUSR) ? 'r' : '-';
btm_buffer[2] = (mid_dir.current_file->permissions & S_IWUSR) ? 'w' : '-';
btm_buffer[3] = (mid_dir.current_file->permissions & S_IXUSR) ? 'x' : '-';
btm_buffer[4] = (mid_dir.current_file->permissions & S_IRGRP) ? 'r' : '-';
btm_buffer[5] = (mid_dir.current_file->permissions & S_IWGRP) ? 'w' : '-';
btm_buffer[6] = (mid_dir.current_file->permissions & S_IXGRP) ? 'x' : '-';
btm_buffer[7] = (mid_dir.current_file->permissions & S_IROTH) ? 'r' : '-';
btm_buffer[8] = (mid_dir.current_file->permissions & S_IWOTH) ? 'w' : '-';
btm_buffer[9] = (mid_dir.current_file->permissions & S_IXOTH) ? 'x' : '-';
if (mid_dir.current_file != NULL) {
btm_buffer[0] = (S_ISLNK(mid_dir.current_file->permissions)) ? 'l':
(S_ISDIR(mid_dir.current_file->permissions) ? 'd': '-');
btm_buffer[1] = (mid_dir.current_file->permissions & S_IRUSR) ? 'r' : '-';
btm_buffer[2] = (mid_dir.current_file->permissions & S_IWUSR) ? 'w' : '-';
btm_buffer[3] = (mid_dir.current_file->permissions & S_IXUSR) ? 'x' : '-';
btm_buffer[4] = (mid_dir.current_file->permissions & S_IRGRP) ? 'r' : '-';
btm_buffer[5] = (mid_dir.current_file->permissions & S_IWGRP) ? 'w' : '-';
btm_buffer[6] = (mid_dir.current_file->permissions & S_IXGRP) ? 'x' : '-';
btm_buffer[7] = (mid_dir.current_file->permissions & S_IROTH) ? 'r' : '-';
btm_buffer[8] = (mid_dir.current_file->permissions & S_IWOTH) ? 'w' : '-';
btm_buffer[9] = (mid_dir.current_file->permissions & S_IXOTH) ? 'x' : '-';
}