mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 18:30:15 -04:00
now accounting for hardlinks & refactored sorting
This commit is contained in:
18
dir.c
18
dir.c
@@ -91,9 +91,15 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
dir_content[i].color_pair = COLOR_DIR;
|
dir_content[i].color_pair = COLOR_DIR;
|
||||||
dir_content[i].file_size = get_dir_size(full_path);
|
dir_content[i].file_size = get_dir_size(full_path);
|
||||||
} else if (S_ISLNK(file->st_mode)) {
|
} else if (S_ISLNK(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_SYMLINK;
|
stat(full_path, file);
|
||||||
dir_content[i].color_pair = COLOR_SYMLINK;
|
if (S_ISDIR(file->st_mode)) {
|
||||||
dir_content[i].file_size = get_dir_size(full_path);
|
dir_content[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK;
|
||||||
|
dir_content[i].color_pair = COLOR_SYMLINK;
|
||||||
|
dir_content[i].file_size = get_dir_size(full_path);
|
||||||
|
} else {
|
||||||
|
dir_content[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
|
||||||
|
dir_content[i].color_pair = COLOR_SYMLINK;
|
||||||
|
}
|
||||||
} else if (file->st_mode & S_IXUSR) {
|
} else if (file->st_mode & S_IXUSR) {
|
||||||
dir_content[i].file_type = FILE_TYPE_EXEC;
|
dir_content[i].file_type = FILE_TYPE_EXEC;
|
||||||
dir_content[i].color_pair = COLOR_EXEC;
|
dir_content[i].color_pair = COLOR_EXEC;
|
||||||
@@ -239,7 +245,7 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
} while (file_size > 1 && size_index < size_unit_count);
|
} while (file_size > 1 && size_index < size_unit_count);
|
||||||
size_char = size_unit[(unsigned)size_index];
|
size_char = size_unit[(unsigned)size_index];
|
||||||
|
|
||||||
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {
|
if (dir_content[i].file_type &= FILE_TYPE_DIR) {
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1);
|
offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1);
|
||||||
} else if (size_char =='B') {
|
} else if (size_char =='B') {
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
||||||
@@ -300,7 +306,7 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
|
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
|
||||||
free(file_name);
|
free(file_name);
|
||||||
|
|
||||||
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {
|
if (dir_content[i].file_type &= FILE_TYPE_DIR) {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size);
|
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size);
|
||||||
}else if (size_char =='B') {
|
}else if (size_char =='B') {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
||||||
@@ -381,7 +387,7 @@ void dir_init(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
char recursive_delete(file current_file){
|
char recursive_delete(file current_file){
|
||||||
if (current_file.file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
|
if (current_file.file_type & FILE_TYPE_DIR) {
|
||||||
unsigned int file_modifiers_tmp = file_modifiers;
|
unsigned int file_modifiers_tmp = file_modifiers;
|
||||||
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
unsigned long current_file_count = get_dir_size(current_file.file_name);
|
unsigned long current_file_count = get_dir_size(current_file.file_name);
|
||||||
|
@@ -254,7 +254,7 @@ void move_right(){
|
|||||||
if (mid_content->file_name[0] == '\0') {
|
if (mid_content->file_name[0] == '\0') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mid_content[selected_file_current].file_type == FILE_TYPE_DIR || mid_content[selected_file_current].file_type == FILE_TYPE_SYMLINK) {
|
if (mid_content[selected_file_current].file_type &= FILE_TYPE_DIR) {
|
||||||
if (chdir(mid_content[selected_file_current].file_name) != 0) {
|
if (chdir(mid_content[selected_file_current].file_name) != 0) {
|
||||||
FAIL("move_right", "unhandled error of chdir");
|
FAIL("move_right", "unhandled error of chdir");
|
||||||
} else {
|
} else {
|
||||||
@@ -465,7 +465,7 @@ void delete(){
|
|||||||
btm_buffer = concat("deleted: ", file_str);
|
btm_buffer = concat("deleted: ", file_str);
|
||||||
} else {
|
} else {
|
||||||
free(btm_buffer);
|
free(btm_buffer);
|
||||||
if (mid_content[selected_file_current].file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
|
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
|
||||||
recursive_delete(mid_content[selected_file_current]);
|
recursive_delete(mid_content[selected_file_current]);
|
||||||
}
|
}
|
||||||
remove(mid_content[selected_file_current].file_name);
|
remove(mid_content[selected_file_current].file_name);
|
||||||
|
92
sorting.c
92
sorting.c
@@ -12,12 +12,14 @@ extern unsigned int settings;
|
|||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
|
|
||||||
int skip_hidden_files(const struct dirent *entry){
|
int skip_hidden_files(const struct dirent *entry){
|
||||||
|
|
||||||
if (entry->d_name[0] == '.') {
|
if (entry->d_name[0] == '.') {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int skip_dot(const struct dirent *entry){
|
int skip_dot(const struct dirent *entry){
|
||||||
|
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -26,10 +28,10 @@ int skip_dot(const struct dirent *entry){
|
|||||||
|
|
||||||
int sort_natural(const void *file0, const void *file1){
|
int sort_natural(const void *file0, const void *file1){
|
||||||
|
|
||||||
if (((file*)file0)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR) && !(((file*)file1)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR))) {
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!(((file*)file0)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && ((file*)file1)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
const unsigned char *a = (unsigned char*)((file*)file0)->file_name;
|
const unsigned char *a = (unsigned char*)((file*)file0)->file_name;
|
||||||
@@ -99,70 +101,58 @@ int sort_natural(const void *file0, const void *file1){
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
int sort_alpha(const void *file0, const void *file1){
|
int sort_alpha(const void *file0, const void *file1){
|
||||||
char *file_name0 = ((file*)file0)->file_name;
|
|
||||||
char *file_name1 = ((file*)file1)->file_name;
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return strcmp(file_name0, file_name1);
|
return -1;
|
||||||
|
}
|
||||||
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strcmp(((file*)file0)->file_name, ((file*)file1)->file_name);
|
||||||
}
|
}
|
||||||
int sort_random(const void *file0, const void *file1){
|
int sort_random(const void *file0, const void *file1){
|
||||||
|
|
||||||
if (((file*)file0)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR) && !(((file*)file1)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR))) {
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!(((file*)file0)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && ((file*)file1)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((rand()%3)-1);
|
return ((rand()%3)-1);
|
||||||
|
|
||||||
}
|
}
|
||||||
int sort_type(const void *file0, const void *file1){
|
int sort_type(const void *file0, const void *file1){
|
||||||
unsigned char file_type0 = ((file*)file0)->file_type;
|
|
||||||
unsigned char file_type1 = ((file*)file1)->file_type;
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
char *file_name0 = ((file*)file0)->file_name;
|
|
||||||
char *file_name1 = ((file*)file1)->file_name;
|
|
||||||
if (file_type0 == file_type1) {
|
|
||||||
return strcasecmp(file_name0, file_name1);
|
|
||||||
} else if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
|
||||||
return -1;
|
|
||||||
} else if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
if (file_type0 > file_type1) {
|
|
||||||
return -1;
|
return -1;
|
||||||
} else if (file_type0 < file_type1) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return strcasecmp(file_name0, file_name1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((file*)file0)->file_type == ((file*)file1)->file_type) {
|
||||||
|
/*somehow relying on the else below, occasionaly trips either one of the checked for conditions*/
|
||||||
|
return strcasecmp(((file*)file0)->file_name, ((file*)file1)->file_name);
|
||||||
|
} else if (((file*)file0)->file_type > ((file*)file1)->file_type) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
int sort_size(const void *file0, const void *file1){
|
int sort_size(const void *file0, const void *file1){
|
||||||
unsigned char file_type0 = ((file*)file0)->file_type;
|
|
||||||
unsigned char file_type1 = ((file*)file1)->file_type;
|
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
unsigned long file_size0 = ((file*)file0)->file_size;
|
|
||||||
unsigned long file_size1 = ((file*)file1)->file_size;
|
|
||||||
char *file_name0 = ((file*)file0)->file_name;
|
|
||||||
char *file_name1 = ((file*)file1)->file_name;
|
|
||||||
if (file_type0 == file_type1) {
|
|
||||||
if (file_size0 > file_size1) {
|
|
||||||
return -1;
|
return -1;
|
||||||
} else if (file_size0 < file_size1) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return strcasecmp(file_name0, file_name1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
|
||||||
return -1;
|
|
||||||
} else if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
if (file_size0 > file_size1) {
|
|
||||||
return -1;
|
|
||||||
} else if (file_size0 < file_size1) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return strcasecmp(file_name0, file_name1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((file*)file0)->file_size == ((file*)file1)->file_size) {
|
||||||
|
return strcasecmp(((file*)file0)->file_name, ((file*)file1)->file_name);
|
||||||
|
} else if (((file*)file0)->file_size > ((file*)file1)->file_size) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
@@ -156,7 +156,7 @@ void *thread_rgt(){
|
|||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
if (mid_content[selected_file_current].permissions & S_IRUSR) {
|
if (mid_content[selected_file_current].permissions & S_IRUSR) {
|
||||||
if (file_current.file_type == FILE_TYPE_DIR || file_current.file_type == FILE_TYPE_SYMLINK) {
|
if (file_current.file_type &= FILE_TYPE_DIR) {
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
#endif
|
#endif
|
||||||
@@ -281,7 +281,7 @@ void *thread_btm(){
|
|||||||
unsigned long i;
|
unsigned long i;
|
||||||
unsigned long total_dir_size = 0;
|
unsigned long total_dir_size = 0;
|
||||||
for(i = 0; i < mid_file_count; i++) {
|
for(i = 0; i < mid_file_count; i++) {
|
||||||
if (!(mid_content[i].file_type & (FILE_TYPE_DIR | FILE_TYPE_SYMLINK))) {
|
if (!(mid_content[i].file_type & (FILE_TYPE_DIR))) {
|
||||||
total_dir_size += mid_content[i].file_size;
|
total_dir_size += mid_content[i].file_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user