static void add_hierarchy_to_namelist (char *path, dev_t device) { char *buffer = get_directory_contents (path, device); { struct name *name; for (name = name_list_head; name; name = name->next) if (strcmp (name->name, path) == 0) break; if (name) name->dir_contents = buffer ? buffer : "\0\0\0\0"; } if (buffer) { size_t name_length = strlen (path); size_t allocated_length = (name_length >= NAME_FIELD_SIZE ? name_length + NAME_FIELD_SIZE : NAME_FIELD_SIZE); char *name_buffer = xmalloc (allocated_length + 1); /* FIXME: + 2 above? */ char *string; size_t string_length; strcpy (name_buffer, path); if (name_buffer[name_length - 1] != '/') { name_buffer[name_length++] = '/'; name_buffer[name_length] = '\0'; } for (string = buffer; *string; string += string_length + 1) { string_length = strlen (string); if (*string == 'D') { if (name_length + string_length >= allocated_length) { while (name_length + string_length >= allocated_length) allocated_length += NAME_FIELD_SIZE; name_buffer = (char *) xrealloc (name_buffer, allocated_length + 1); } strcpy (name_buffer + name_length, string + 1); add_name (name_buffer); add_hierarchy_to_namelist (name_buffer, device); } } free (name_buffer); } }
void collect_and_sort_names (void) { struct name *name; struct name *next_name; int counter; struct stat stat_info; name_gather (); if (listed_incremental_option) read_directory_file (); if (!name_list_head) add_name ("."); for (name = name_list_head; name; name = next_name) { next_name = name->next; if (name->match_found || name->dir_contents) continue; if (name->is_wildcard) /* FIXME: just skip wildcards for now */ continue; if (name->change_dir) if (chdir (name->change_dir) < 0) { ERROR ((0, errno, _("Cannot chdir to %s"), name->change_dir)); continue; } if ( #ifdef AIX statx (name->name, &stat_info, STATSIZE, STX_HIDDEN | STX_LINK) #else lstat (name->name, &stat_info) < 0 #endif ) { ERROR ((0, errno, _("Cannot stat %s"), name->name)); continue; } if (S_ISDIR (stat_info.st_mode)) { name->match_found = true; add_hierarchy_to_namelist (name->name, stat_info.st_dev); } } counter = 0; for (name = name_list_head; name; name = name->next) counter++; name_list_head = (struct name *) merge_sort ((voidstar) name_list_head, counter, (char *) (&(name_list_head->next)) - (char *) name_list_head, compare_names); for (name = name_list_head; name; name = name->next) name->match_found = false; if (listed_incremental_option) write_dir_file (); }
static void add_hierarchy_to_namelist (struct name *name, dev_t device, bool cmdline) { const char *buffer; name_fill_directory (name, device, cmdline); buffer = directory_contents (name->directory); if (buffer) { struct name *child_head = NULL, *child_tail = NULL; size_t name_length = name->length; size_t allocated_length = (name_length >= NAME_FIELD_SIZE ? name_length + NAME_FIELD_SIZE : NAME_FIELD_SIZE); char *namebuf = xmalloc (allocated_length + 1); /* FIXME: + 2 above? */ const char *string; size_t string_length; int change_dir = name->change_dir; strcpy (namebuf, name->name); if (! ISSLASH (namebuf[name_length - 1])) { namebuf[name_length++] = '/'; namebuf[name_length] = '\0'; } for (string = buffer; *string; string += string_length + 1) { string_length = strlen (string); if (*string == 'D') { struct name *np; if (allocated_length <= name_length + string_length) { do { allocated_length *= 2; if (! allocated_length) xalloc_die (); } while (allocated_length <= name_length + string_length); namebuf = xrealloc (namebuf, allocated_length + 1); } strcpy (namebuf + name_length, string + 1); np = addname (namebuf, change_dir, false, name); if (!child_head) child_head = np; else child_tail->sibling = np; child_tail = np; add_hierarchy_to_namelist (np, device, false); } } free (namebuf); name->child = child_head; } }
void collect_and_sort_names (void) { struct name *name; struct name *next_name, *prev_name; int num_names; struct stat statbuf; Hash_table *nametab; name_gather (); if (!namelist) addname (".", 0, false, NULL); if (listed_incremental_option) { switch (chdir_count ()) { case 0: break; case 1: if (namelist->change_dir == 0) USAGE_ERROR ((0, 0, _("Using -C option inside file list is not " "allowed with --listed-incremental"))); break; default: USAGE_ERROR ((0, 0, _("Only one -C option is allowed with " "--listed-incremental"))); } read_directory_file (); } num_names = 0; for (name = namelist; name; name = name->next, num_names++) { if (name->found_count || name->directory) continue; if (name->matching_flags & EXCLUDE_WILDCARDS) /* NOTE: EXCLUDE_ANCHORED is not relevant here */ /* FIXME: just skip regexps for now */ continue; chdir_do (name->change_dir); if (name->name[0] == 0) continue; if (deref_stat (dereference_option, name->name, &statbuf) != 0) { stat_diag (name->name); continue; } if (S_ISDIR (statbuf.st_mode)) { name->found_count++; add_hierarchy_to_namelist (name, statbuf.st_dev, true); } } namelist = merge_sort (namelist, num_names, compare_names); num_names = 0; nametab = hash_initialize (0, 0, name_hash, name_compare, NULL); for (name = namelist; name; name = next_name) { next_name = name->next; name->caname = normalize_filename (name->name); if (prev_name) { struct name *p = hash_lookup (nametab, name); if (p) { /* Keep the one listed in the command line */ if (!name->parent) { if (p->child) rebase_child_list (p->child, name); /* FIXME: remove_directory (p->caname); ? */ remname (p); free_name (p); num_names--; } else { if (name->child) rebase_child_list (name->child, p); /* FIXME: remove_directory (name->caname); ? */ remname (name); free_name (name); continue; } } } name->found_count = 0; if (!hash_insert (nametab, name)) xalloc_die (); prev_name = name; num_names++; } nametail = prev_name; hash_free (nametab); namelist = merge_sort (namelist, num_names, compare_names_found); if (listed_incremental_option) { for (name = namelist; name && name->name[0] == 0; name++) ; if (name) append_incremental_renames (name->directory); } }
void collect_and_sort_names (void) { struct name *name; struct name *next_name; int num_names; struct stat statbuf; name_gather (); if (listed_incremental_option) read_directory_file (); if (!namelist) addname ("."); for (name = namelist; name; name = next_name) { next_name = name->next; if (name->found || name->dir_contents) continue; if (name->regexp) /* FIXME: just skip regexps for now */ continue; if (name->change_dir) if (chdir (name->change_dir) < 0) { ERROR ((0, errno, _("Cannot chdir to %s"), name->change_dir)); continue; } if ( #ifdef AIX statx (name->name, &statbuf, STATSIZE, STX_HIDDEN | STX_LINK) #else lstat (name->name, &statbuf) < 0 #endif ) { ERROR ((0, errno, _("Cannot stat %s"), name->name)); continue; } if (S_ISDIR (statbuf.st_mode)) { name->found = 1; add_hierarchy_to_namelist (name->name, statbuf.st_dev); } } num_names = 0; for (name = namelist; name; name = name->next) num_names++; namelist = (struct name *) merge_sort ((voidstar) namelist, num_names, (char *) (&(namelist->next)) - (char *) namelist, compare_names); for (name = namelist; name; name = name->next) name->found = 0; if (listed_incremental_option) write_dir_file (); }