From df59690240b9a41d59ebe9e809faffd93f340020 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Fri, 7 Aug 2009 22:40:06 +0300 Subject: [PATCH] Minor fixes. * src/common.h (rebase_directory): New prototype. * src/incremen.c (rebase_directory): Use replace_prefix. * src/names.c (collect_and_sort_names): Abort if hash_insert fails. --- .gitignore | 1 + src/common.h | 4 +++- src/incremen.c | 14 ++------------ src/names.c | 14 +++++--------- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 6f85d55..c978699 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ Makefile Makefile.in aclocal.m4 autom4te.cache +build-aux build-aux/ config.h config.h.in diff --git a/src/common.h b/src/common.h index d734b64..9905817 100644 --- a/src/common.h +++ b/src/common.h @@ -505,7 +505,6 @@ char *dumpdir_locate (dumpdir_t dump, const char *name); char *dumpdir_next (dumpdir_iter_t itr); char *dumpdir_first (dumpdir_t dump, int all, dumpdir_iter_t *pitr); - const char *scan_directory (char *dir_name, dev_t device, bool cmdline); const char *append_incremental_renames (const char *dump); void read_directory_file (void); @@ -513,6 +512,9 @@ void write_directory_file (void); void purge_directory (char const *directory_name); void list_dumpdir (char *buffer, size_t size); void update_parent_directory (const char *name); +void rebase_directory (const char *name, size_t old_prefix_len, + const char *old_prefix, + const char *new_prefix); size_t dumpdir_size (const char *p); bool is_dumpdir (struct tar_stat_info *stat_info); diff --git a/src/incremen.c b/src/incremen.c index 5641217..f5631a1 100644 --- a/src/incremen.c +++ b/src/incremen.c @@ -399,18 +399,8 @@ rebase_directory (const char *name, size_t old_prefix_len, { struct directory *dir = find_directory (name); if (dir) - { - size_t len = strlen (dir->name); - if (len > old_prefix_len - && memcmp (dir->name, old_prefix, old_prefix_len) == 0) - { - char *newp = xmalloc (len - old_prefix_len + strlen (new_prefix)); - strcpy (newp, new_prefix); - strcat (newp, dir->name + old_prefix_len); - free (dir->name); - dir->name = newp; - } - } + replace_prefix (&dir->name, old_prefix, old_prefix_len, + new_prefix, strlen (new_prefix)); } /* Return a directory entry for a given combination of device and inode diff --git a/src/names.c b/src/names.c index eaa94d2..0a282b9 100644 --- a/src/names.c +++ b/src/names.c @@ -912,9 +912,9 @@ collect_and_sort_names (void) read_directory_file (); } - for (name = namelist; name; name = next_name) + num_names = 0; + for (name = namelist; name; name = name->next, num_names++) { - next_name = name->next; if (name->found_count || name->dir_contents) continue; if (name->matching_flags & EXCLUDE_WILDCARDS) @@ -934,15 +934,10 @@ collect_and_sort_names (void) if (S_ISDIR (statbuf.st_mode)) { name->found_count++; - if (name->found_count == 1) - add_hierarchy_to_namelist (name, statbuf.st_dev, true); + add_hierarchy_to_namelist (name, statbuf.st_dev, true); } } - num_names = 0; - for (name = namelist; name; name = name->next) - num_names++; - namelist = merge_sort (namelist, num_names, compare_names); num_names = 0; @@ -980,7 +975,8 @@ collect_and_sort_names (void) } } name->found_count = 0; - hash_insert (nametab, name); + if (!hash_insert (nametab, name)) + xalloc_die (); prev_name = name; num_names++; } -- 2.45.2