diff --git a/src/browser.c b/src/browser.c index 103983495eb4863efe8d135474f367e47bbb8432..f2faddaea17b46c6511c19e382e9251944e61532 100644 --- a/src/browser.c +++ b/src/browser.c @@ -187,9 +187,9 @@ void browse_draw() { /* second line - the path */ mvhline(1, 0, '-', wincols); - if(t) { + if(dirlist_par) { mvaddch(1, 3, ' '); - tmp = getpath(t->parent); + tmp = getpath(dirlist_par); mvaddstr(1, 4, cropstr(tmp, wincols-8)); mvaddch(1, 4+((int)strlen(tmp) > wincols-8 ? wincols-8 : (int)strlen(tmp)), ' '); } @@ -363,8 +363,8 @@ int browse_key(int ch) { case 10: case KEY_RIGHT: case 'l': - if(sel != NULL && sel->sub != NULL) { - dirlist_open(sel->sub); + if(sel != NULL && sel->flags & FF_DIR) { + dirlist_open(sel == dirlist_parent ? dirlist_par->parent : sel); dirlist_top(-3); } info_show = 0; @@ -372,8 +372,8 @@ int browse_key(int ch) { case KEY_LEFT: case 'h': case '<': - if(sel != NULL && sel->parent->parent != NULL) { - dirlist_open(sel->parent); + if(dirlist_par && dirlist_par->parent != NULL) { + dirlist_open(dirlist_par->parent); dirlist_top(-3); } info_show = 0; @@ -385,10 +385,10 @@ int browse_key(int ch) { message = "Directory imported from file, won't refresh."; break; } - if(sel != NULL) { + if(dirlist_par) { dir_ui = 2; - dir_mem_init(sel->parent); - dir_scan_init(getpath(sel->parent)); + dir_mem_init(dirlist_par); + dir_scan_init(getpath(dirlist_par)); } info_show = 0; break; @@ -425,7 +425,7 @@ int browse_key(int ch) { info_show = 0; if((t = dirlist_get(1)) == sel) if((t = dirlist_get(-1)) == sel || t == dirlist_parent) - t = sel->parent; + t = NULL; delete_init(sel, t); break; } @@ -441,9 +441,9 @@ int browse_key(int ch) { } -void browse_init(struct dir *cur) { +void browse_init(struct dir *par) { pstate = ST_BROWSE; message = NULL; - dirlist_open(cur); + dirlist_open(par); } diff --git a/src/delete.c b/src/delete.c index 015af788905068ab1d44fb58d1f192552a4a7e43..9c358c1ff0e6cd43af8c2b960132536a37b5d6ad 100644 --- a/src/delete.c +++ b/src/delete.c @@ -209,11 +209,13 @@ delete_nxt: void delete_process() { + struct dir *par; + /* confirm */ seloption = 1; while(state == DS_CONFIRM && !noconfirm) if(input_handle(0)) { - browse_init(root); + browse_init(root->parent); return; } @@ -229,13 +231,13 @@ void delete_process() { /* delete */ seloption = 0; state = DS_PROGRESS; - if(delete_dir(root)) - browse_init(root); - else { + par = root->parent; + delete_dir(root); + if(nextsel) nextsel->flags |= FF_BSEL; - browse_init(nextsel); + browse_init(par); + if(nextsel) dirlist_top(-4); - } } diff --git a/src/dir_import.c b/src/dir_import.c index 40a3a53de9fd59b45a762eb19f4a35dfe527052c..03bcfbf731e68e7d057a370adbbaeed7cbc15ba5 100644 --- a/src/dir_import.c +++ b/src/dir_import.c @@ -547,8 +547,6 @@ static int item(uint64_t dev) { if(!isroot) dir_curpath_leave(); - else /* The root item must not be empty. */ - E(ctx->items <= 1, "Empty directory"); return 0; } diff --git a/src/dir_mem.c b/src/dir_mem.c index 888d698ce6128160029ec6ef99d8deb5f1ee4698..73dd84889af17ef8942104ef68fcbed7f6355e8f 100644 --- a/src/dir_mem.c +++ b/src/dir_mem.c @@ -198,7 +198,7 @@ static int final(int fail) { freedir(orig); } - browse_init(root->sub); + browse_init(root); dirlist_top(-3); return 0; } diff --git a/src/dir_scan.c b/src/dir_scan.c index 2953421e0ec9aca2dfdfdcea8160ad087302b97c..e3d93e8e8e8aaad171cb21179c9da68042baab3a 100644 --- a/src/dir_scan.c +++ b/src/dir_scan.c @@ -266,12 +266,6 @@ static int process() { if(!dir_fatalerr && !(dir = dir_read(&fail))) dir_seterr("Error reading directory: %s", strerror(errno)); - /* Special case: empty directory = error */ - if(!dir_fatalerr && !*dir) { - dir_seterr("Directory empty"); - free(dir); - } - if(!dir_fatalerr) { curdev = (uint64_t)fs.st_dev; d = dir_createstruct(dir_curpath); diff --git a/src/dirlist.c b/src/dirlist.c index a61b8168b84e3808e5900ba46774dfbe52464a3b..7b7fa9e473de96e55614e5fc5d9761feed428904 100644 --- a/src/dirlist.c +++ b/src/dirlist.c @@ -29,7 +29,8 @@ /* public variables */ -struct dir *dirlist_parent = NULL; +struct dir *dirlist_parent = NULL, + *dirlist_par = NULL; int64_t dirlist_maxs = 0, dirlist_maxa = 0; @@ -186,29 +187,33 @@ static void dirlist_fixup() { void dirlist_open(struct dir *d) { + dirlist_par = d; + /* set the head of the list */ - head_real = head = d == NULL ? NULL : d->parent == NULL ? d->sub : d->parent->sub; + head_real = head = d == NULL ? NULL : d->sub; /* reset internal status */ dirlist_maxs = dirlist_maxa = 0; /* stop if this is not a directory list we can work with */ - if(head == NULL) { + if(d == NULL) { dirlist_parent = NULL; return; } /* sort the dir listing */ - head_real = head = dirlist_sort(head); + if(head) + head_real = head = dirlist_sort(head); /* set the reference to the parent dir */ dirlist_parent_alloc.flags &= ~FF_BSEL; - if(head->parent->parent) { + dirlist_parent_alloc.flags |= FF_DIR; + if(d->parent) { dirlist_parent = &dirlist_parent_alloc; strcpy(dirlist_parent->name, ".."); dirlist_parent->next = head; - dirlist_parent->parent = head->parent; - dirlist_parent->sub = head->parent; + dirlist_parent->parent = d; + dirlist_parent->sub = d; head = dirlist_parent; } else dirlist_parent = NULL; diff --git a/src/dirlist.h b/src/dirlist.h index c69e117835941f7ec0a492064cee62f10e96b4dc..f4bf1af839f8bb1a18d2055be2881e03ee66751f 100644 --- a/src/dirlist.h +++ b/src/dirlist.h @@ -68,6 +68,9 @@ void dirlist_set_hidden(int hidden); /* The 'reference to parent dir' */ extern struct dir *dirlist_parent; +/* The actual parent dir */ +extern struct dir *dirlist_par; + /* current sorting configuration (set with dirlist_set_sort()) */ extern int dirlist_sort_desc, dirlist_sort_col, dirlist_sort_df;