* dir.c (do_sort): Do not try to reorder the entries so that ".." becomes

the first entry.
(do_load_dir): When filling the list of directory entriesmake sure that
".." occupies the first element.
(do_reload_dir): Likewise.
This commit is contained in:
Pavel Tsekov 2006-01-29 11:23:36 +00:00
parent b3fa1f0a3e
commit d05ad82ea6
2 changed files with 36 additions and 23 deletions

View File

@ -1,3 +1,11 @@
2006-01-29 Pavel Tsekov <ptsekov@gmx.net>
* dir.c (do_sort): Do not try to reorder the entries so
that ".." becomes the first entry.
(do_load_dir): When filling the list of directory entries
make sure that ".." occupies the first element.
(do_reload_dir): Likewise.
2006-01-29 Julian Mehnle <julian@mehnle.net> 2006-01-29 Julian Mehnle <julian@mehnle.net>
* cmd.c: When invoking external viewer, probe VIEWER environment * cmd.c: When invoking external viewer, probe VIEWER environment

View File

@ -310,19 +310,14 @@ do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitiv
{ {
int i; int i;
int dot_dot_found = 0; int dot_dot_found = 0;
file_entry tmp_fe;
for (i = 0; i < top + 1; i++) { /* put ".." first in list */ if (top == 0)
if (!strcmp (list->list [i].fname, "..")) { return;
/* If there is an ".." entry the caller must take care to
ensure that it occupies the first list element. */
if (!strcmp (list->list [0].fname, ".."))
dot_dot_found = 1; dot_dot_found = 1;
if (i > 0) { /* swap [i] and [0] */
memcpy (&tmp_fe, &(list->list [0]), sizeof (file_entry));
memcpy (&(list->list [0]), &(list->list [i]), sizeof (file_entry));
memcpy (&(list->list [i]), &tmp_fe, sizeof (file_entry));
}
break;
}
}
reverse = reverse_f ? -1 : 1; reverse = reverse_f ? -1 : 1;
case_sensitive = case_sensitive_f; case_sensitive = case_sensitive_f;
@ -476,12 +471,20 @@ do_load_dir (const char *path, dir_list *list, sortfn *sort, int reverse,
int next_free = 0; int next_free = 0;
struct stat st; struct stat st;
/* ".." (if any) must be the first entry in the list */
if (set_zero_dir (list) == 0)
return next_free;
next_free++;
dirp = mc_opendir (path); dirp = mc_opendir (path);
if (!dirp) { if (!dirp) {
message (1, MSG_ERROR, _("Cannot read directory contents")); message (1, MSG_ERROR, _("Cannot read directory contents"));
return set_zero_dir (list); return next_free;
} }
tree_store_start_check (path); tree_store_start_check (path);
/* Do not add a ".." entry to the root directory */
if (!strcmp (path, "/"))
next_free--;
while ((dp = mc_readdir (dirp))) { while ((dp = mc_readdir (dirp))) {
status = status =
handle_dirent (list, filter, dp, &st, next_free, &link_to_dir, handle_dirent (list, filter, dp, &st, next_free, &link_to_dir,
@ -506,12 +509,7 @@ do_load_dir (const char *path, dir_list *list, sortfn *sort, int reverse,
} }
if (next_free) { if (next_free) {
/* Add ".." except the root directory */
if (strcmp (path, "/") != 0)
add_dotdot_to_list (list, next_free++);
do_sort (list, sort, next_free - 1, reverse, case_sensitive); do_sort (list, sort, next_free - 1, reverse, case_sensitive);
} else {
next_free = set_zero_dir (list);
} }
mc_closedir (dirp); mc_closedir (dirp);
@ -602,6 +600,17 @@ do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count,
} }
} }
/* Add ".." except to the root directory. The ".." entry
(if any) must be the first in the list. */
if (strcmp (path, "/") != 0) {
if (set_zero_dir (list) == 0) {
clean_dir (list, count);
clean_dir (&dir_copy, count);
return next_free;
}
next_free++;
}
while ((dp = mc_readdir (dirp))) { while ((dp = mc_readdir (dirp))) {
status = status =
handle_dirent (list, filter, dp, &st, next_free, &link_to_dir, handle_dirent (list, filter, dp, &st, next_free, &link_to_dir,
@ -653,12 +662,8 @@ do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count,
tree_store_end_check (); tree_store_end_check ();
g_hash_table_destroy (marked_files); g_hash_table_destroy (marked_files);
if (next_free) { if (next_free) {
/* Add ".." except the root directory */
if (strcmp (path, "/") != 0)
add_dotdot_to_list (list, next_free++);
do_sort (list, sort, next_free - 1, rev, case_sensitive); do_sort (list, sort, next_free - 1, rev, case_sensitive);
} else }
next_free = set_zero_dir (list);
clean_dir (&dir_copy, count); clean_dir (&dir_copy, count);
return next_free; return next_free;
} }