diff --git a/src/filemanager/dir.c b/src/filemanager/dir.c index 52043c1cf..233f2bace 100644 --- a/src/filemanager/dir.c +++ b/src/filemanager/dir.c @@ -287,6 +287,41 @@ dir_list_grow (dir_list * list, int delta) return TRUE; } +/* --------------------------------------------------------------------------------------------- */ +/** + * Append file info to the directory list. + * + * @param list directory list + * @param fname file name + * @param st file stat info + * @param link_to_dir is file link to directory + * @param stale_link is file stale elink + * + * @return FALSE on failure, TRUE on success + */ + +gboolean +dir_list_append (dir_list * list, const char *fname, const struct stat *st, + gboolean link_to_dir, gboolean stale_link) +{ + /* Need to grow the *list? */ + if (list->len == list->size && !dir_list_grow (list, RESIZE_STEPS)) + return FALSE; + + list->list[list->len].fnamelen = strlen (fname); + list->list[list->len].fname = g_strndup (fname, list->list[list->len].fnamelen); + list->list[list->len].f.marked = 0; + list->list[list->len].f.link_to_dir = link_to_dir ? 1 : 0; + list->list[list->len].f.stale_link = stale_link ? 1 : 0; + list->list[list->len].f.dir_size_computed = 0; + list->list[list->len].st = *st; + list->list[list->len].sort_key = NULL; + list->list[list->len].second_sort_key = NULL; + list->len++; + + return TRUE; +} + /* --------------------------------------------------------------------------------------------- */ int @@ -606,20 +641,9 @@ do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, { if (!handle_dirent (dp, fltr, &st, &link_to_dir, &stale_link)) continue; - /* Need to grow the *list? */ - if (list->len == list->size && !dir_list_grow (list, RESIZE_STEPS)) - goto ret; - list->list[list->len].fnamelen = strlen (dp->d_name); - list->list[list->len].fname = g_strndup (dp->d_name, list->list[list->len].fnamelen); - list->list[list->len].f.marked = 0; - list->list[list->len].f.link_to_dir = link_to_dir; - list->list[list->len].f.stale_link = stale_link; - list->list[list->len].f.dir_size_computed = 0; - list->list[list->len].st = st; - list->list[list->len].sort_key = NULL; - list->list[list->len].second_sort_key = NULL; - list->len++; + if (!dir_list_append (list, dp->d_name, &st, link_to_dir != 0, stale_link != 0)) + goto ret; if ((list->len & 31) == 0) rotate_dash (TRUE); @@ -711,8 +735,8 @@ do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, { if (!handle_dirent (dp, fltr, &st, &link_to_dir, &stale_link)) continue; - /* Need to grow the *list? */ - if (list->len == list->size && !dir_list_grow (list, RESIZE_STEPS)) + + if (!dir_list_append (list, dp->d_name, &st, link_to_dir != 0, stale_link != 0)) { mc_closedir (dirp); /* Norbert (Feb 12, 1997): @@ -730,7 +754,7 @@ do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, return; } - list->list[list->len].f.marked = 0; + list->list[list->len - 1].f.marked = 0; /* * If we have marked files in the copy, scan through the copy @@ -739,19 +763,10 @@ do_reload_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, */ if (marked_cnt > 0 && g_hash_table_lookup (marked_files, dp->d_name) != NULL) { - list->list[list->len].f.marked = 1; + list->list[list->len - 1].f.marked = 1; marked_cnt--; } - list->list[list->len].fnamelen = strlen (dp->d_name); - list->list[list->len].fname = g_strndup (dp->d_name, list->list[list->len].fnamelen); - list->list[list->len].f.link_to_dir = link_to_dir; - list->list[list->len].f.stale_link = stale_link; - list->list[list->len].f.dir_size_computed = 0; - list->list[list->len].st = st; - list->list[list->len].sort_key = NULL; - list->list[list->len].second_sort_key = NULL; - list->len++; if ((list->len & 15) == 0) rotate_dash (TRUE); } diff --git a/src/filemanager/dir.h b/src/filemanager/dir.h index bb93e70e1..a48efeb04 100644 --- a/src/filemanager/dir.h +++ b/src/filemanager/dir.h @@ -45,6 +45,8 @@ typedef struct dir_sort_options_struct /*** declarations of public functions ************************************************************/ gboolean dir_list_grow (dir_list * list, int delta); +gboolean dir_list_append (dir_list * list, const char *fname, const struct stat *st, + gboolean link_to_dir, gboolean stale_link); void do_load_dir (const vfs_path_t * vpath, dir_list * list, GCompareFunc sort, const dir_sort_options_t * sort_op, const char *fltr); diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index f5320c0ab..d7df5804a 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -353,20 +353,12 @@ do_external_panelize (char *command) if (!handle_path (name, &st, &link_to_dir, &stale_link)) continue; - /* Need to grow the *list? */ - if (list->len == list->size && !dir_list_grow (list, RESIZE_STEPS)) + + if (!dir_list_append (list, name, &st, link_to_dir != 0, stale_link != 0)) break; - list->list[list->len].fnamelen = strlen (name); - list->list[list->len].fname = g_strndup (name, list->list[list->len].fnamelen); - list->list[list->len].f.link_to_dir = link_to_dir; - list->list[list->len].f.stale_link = stale_link; - list->list[list->len].f.dir_size_computed = 0; - list->list[list->len].st = st; - list->list[list->len].sort_key = NULL; - list->list[list->len].second_sort_key = NULL; - file_mark (current_panel, list->len, 0); - list->len++; + file_mark (current_panel, list->len - 1, 0); + if ((list->len & 31) == 0) rotate_dash (TRUE); }