1
0
mirror of https://gittea.dev/nova/th.git synced 2025-10-21 18:30:15 -04:00

handling of empty dirs

This commit is contained in:
nova
2025-08-24 19:45:08 +02:00
parent ba1e95bca3
commit 4a9c38d034
5 changed files with 65 additions and 40 deletions

View File

@@ -68,35 +68,28 @@ void *thread_mid(void *data){
}
free(mid_content);
mid_file_count = get_dir_size(path);
if (mid_file_count > 0) {
if (mid_file_count != 0) {
mid_content = malloc(mid_file_count * sizeof(file));
memset(mid_content, '\0', mid_file_count * sizeof(file));
get_dir_content(path, &mid_file_count, mid_content);
} else {
selected_file_current = 0;
mid_content = malloc(sizeof(file));
mid_content->status = FILE_STATUS_DIR_EMPTY;
mid_content->file_type = 0;
mid_content->file_size = 0;
mid_content->permissions = 0;
mid_content->color_pair = 0;
mid_content->file_name = "empty dir";
mid_content->file_name = malloc(sizeof(char));
mid_content->file_name[0] = '\0';
mid_file_count = 0;
pthread_cond_signal(&cond_rgt);
pthread_cond_signal(&cond_lft);
free(path);
pthread_mutex_unlock(&mutex_mid);
pthread_exit(0);
}
pthread_mutex_lock(&mutex_selection);
update_selected_file();
pthread_mutex_unlock(&mutex_selection);
}
pthread_cond_signal(&cond_rgt);
pthread_cond_signal(&cond_lft);
@@ -150,35 +143,58 @@ void *thread_rgt(void *data){
pthread_mutex_lock(&mutex_mid);
char *path = malloc(strlen(mid_content[selected_file_current].file_name) + 1);
strcpy(path, mid_content[selected_file_current].file_name);
char *path;
if (mid_file_count != 0) {
path = malloc(strlen(mid_content[selected_file_current].file_name) + 1);
strcpy(path, mid_content[selected_file_current].file_name);
} else {
path = malloc(sizeof(char));
path[0] = '\0';
}
file_current.file_type = mid_content[selected_file_current].file_type;
file_current.file_size = mid_content[selected_file_current].file_size;
file_current.status = mid_content[selected_file_current].status;
pthread_mutex_unlock(&mutex_mid);
if (file_current.file_type == FILE_TYPE_DIR || file_current.file_type == FILE_TYPE_SYMLINK) {
images_clear();
if (mid_content[selected_file_current].permissions & S_IRUSR) {
if (file_current.file_type == FILE_TYPE_DIR || file_current.file_type == FILE_TYPE_SYMLINK) {
images_clear();
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
if (rgt_content[i].file_name) {
free(rgt_content[i].file_name);
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
if (rgt_content[i].file_name) {
free(rgt_content[i].file_name);
}
}
free(rgt_content);
rgt_file_count = get_dir_size(path);
rgt_content = malloc(rgt_file_count * sizeof(file));
memset(rgt_content, '\0', rgt_file_count * sizeof(file));
get_dir_content(path, &rgt_file_count, rgt_content);
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
free(rgt_buffer);
rgt_buffer = malloc(sizeof(char));
rgt_buffer[0] = '\0';
} else {
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
if (rgt_content[i].file_name) {
free(rgt_content[i].file_name);
}
}
free(rgt_content);
rgt_file_count = 0;
rgt_content = malloc(sizeof(file));
free(rgt_buffer);
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
rgt_content->status = FILE_STATUS_HOVER;
rgt_buffer = preview_file(path, file_current.file_size);
}
free(rgt_content);
rgt_file_count = get_dir_size(path);
rgt_content = malloc(rgt_file_count * sizeof(file));
memset(rgt_content, '\0', rgt_file_count * sizeof(file));
get_dir_content(path, &rgt_file_count, rgt_content);
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
free(rgt_buffer);
rgt_buffer = malloc(sizeof(char));
rgt_buffer[0] = '\0';
} else {
unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) {
if (rgt_content[i].file_name) {
@@ -190,14 +206,10 @@ void *thread_rgt(void *data){
rgt_content = malloc(sizeof(file));
free(rgt_buffer);
if (file_current.status & FILE_STATUS_DIR_EMPTY) {
rgt_buffer = "empty dir";
} else {
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
rgt_content->status = FILE_STATUS_HOVER;
rgt_buffer = preview_file(path, file_current.file_size);
}
rgt_buffer = malloc(sizeof(char));
rgt_buffer[0] = '\0';
}
free(path);
pthread_mutex_unlock(&mutex_rgt);