/* Directory attributes. */
struct directory
{
+ struct directory *next;
struct timespec mtime; /* Modification time */
dev_t device_number; /* device number for directory */
ino_t inode_number; /* inode number for directory */
the original directory structure */
const char *tagfile; /* Tag file, if the directory falls under
exclusion_tag_under */
- char name[1]; /* file name of directory */
+ char *name; /* file name of directory */
};
struct dumpdir *
}
\f
+static struct directory *dirhead, *dirtail;
static Hash_table *directory_table;
static Hash_table *directory_meta_table;
make_directory (const char *name)
{
size_t namelen = strlen (name);
- size_t size = offsetof (struct directory, name) + namelen + 1;
- struct directory *directory = xmalloc (size);
+ struct directory *directory = xmalloc (sizeof (*directory));
+ directory->next = NULL;
directory->dump = directory->idump = NULL;
directory->orig = NULL;
directory->flags = false;
- strcpy (directory->name, name);
- if (namelen && ISSLASH (directory->name[namelen - 1]))
- directory->name[namelen - 1] = 0;
+ if (namelen && ISSLASH (name[namelen - 1]))
+ namelen--;
+ directory->name = xmalloc (namelen + 1);
+ memcpy (directory->name, name, namelen);
+ directory->name[namelen] = 0;
directory->tagfile = NULL;
return directory;
}
+static void
+free_directory (struct directory *dir)
+{
+ free (dir->name);
+ free (dir);
+}
+
+static struct directory *
+attach_directory (const char *name)
+{
+ struct directory *dir = make_directory (name);
+ if (dirtail)
+ dirtail->next = dir;
+ else
+ dirhead = dir;
+ dirtail = dir;
+}
+
+\f
+static void
+replace_prefix (char **pname, const char *samp, size_t slen,
+ const char *repl, size_t rlen)
+{
+ char *name = *pname;
+ size_t nlen = strlen (name);
+ if (nlen > slen && memcmp (name, samp, slen) == 0 && ISSLASH (name[slen]))
+ {
+ if (rlen > slen)
+ {
+ name = xrealloc (name, nlen - slen + rlen + 1);
+ *pname = name;
+ }
+ memmove (name + rlen, name + slen, nlen - slen + 1);
+ memcpy (name, repl, rlen);
+ }
+}
+
+void
+dirlist_replace_prefix (const char *pref, const char *repl)
+{
+ struct directory *dp;
+ size_t pref_len = strlen (pref);
+ size_t repl_len = strlen (repl);
+ for (dp = dirhead; dp; dp = dp->next)
+ replace_prefix (&dp->name, pref, pref_len, repl, repl_len);
+}
+
/* Create and link a new directory entry for directory NAME, having a
device number DEV and an inode number INO, with NFS indicating
whether it is an NFS device and FOUND indicating whether we have
dev_t dev, ino_t ino, bool nfs, bool found,
const char *contents)
{
- struct directory *directory = make_directory (name);
+ struct directory *directory = attach_directory (name);
directory->mtime = mtime;
directory->device_number = dev;
{
struct directory *dir = make_directory (name);
struct directory *ret = hash_lookup (directory_table, dir);
- free (dir);
+ free_directory (dir);
return ret;
}
}
dir->device_number = dev;
dir->inode_number = ino;
ret = hash_lookup (directory_meta_table, dir);
- free (dir);
+ free_directory (dir);
return ret;
}
}
stat_data->st_ino);
if (d)
{
- if (verbose_option)
- WARN ((0, 0, _("%s: Directory has been renamed from %s"),
- quotearg_colon (name_buffer),
- quote_n (1, d->name)));
- directory->orig = d;
- DIR_SET_FLAG (directory, DIRF_RENAMED);
+ if (strcmp (d->name, name_buffer))
+ {
+ if (verbose_option)
+ WARN ((0, 0, _("%s: Directory has been renamed from %s"),
+ quotearg_colon (name_buffer),
+ quote_n (1, d->name)));
+ directory->orig = d;
+ DIR_SET_FLAG (directory, DIRF_RENAMED);
+ dirlist_replace_prefix (d->name, name_buffer);
+ }
directory->children = CHANGED_CHILDREN;
}
else
if (d)
{
- if (verbose)
- WARN ((0, 0, _("%s: Directory has been renamed from %s"),
- quotearg_colon (name_buffer),
- quote_n (1, d->name)));
- directory->orig = d;
- DIR_SET_FLAG (directory, DIRF_RENAMED);
+ if (strcmp (d->name, name_buffer))
+ {
+ if (verbose)
+ WARN ((0, 0, _("%s: Directory has been renamed from %s"),
+ quotearg_colon (name_buffer),
+ quote_n (1, d->name)));
+ directory->orig = d;
+ DIR_SET_FLAG (directory, DIRF_RENAMED);
+ dirlist_replace_prefix (d->name, name_buffer);
+ }
directory->children = CHANGED_CHILDREN;
}
else
obstack_grow (stk, s, strlen (s) + 1);
}
-static bool
-rename_handler (void *data, void *proc_data)
+static void
+store_rename (struct directory *dir, struct obstack *stk)
{
- struct directory *dir = data;
- struct obstack *stk = proc_data;
-
if (DIR_IS_RENAMED (dir))
{
struct directory *prev, *p;
obstack_code_rename (stk, "", prev->name);
}
}
- return true;
}
const char *
{
struct obstack stk;
size_t size;
-
- if (directory_table == NULL)
+ struct directory *dp;
+
+ if (dirhead == NULL)
return dump;
obstack_init (&stk);
else
size = 0;
- hash_do_for_each (directory_table, rename_handler, &stk);
+ for (dp = dirhead; dp; dp = dp->next)
+ store_rename (dp, &stk);
+
if (obstack_object_size (&stk) != size)
{
obstack_1grow (&stk, 0);
--- /dev/null
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+# Description: Up to version 1.20, when storing a record for renamed
+# directory in an incremental archive, tar incorrectly flagged all its
+# subdirectories as renamed, which led to problems at archive extraction.
+# References: <00a401c8ecc0$56b7ef30$6a17a8c0@inti.com>
+# Reported by: Enric Hernandez <ehernandez@notariado.org>
+
+AT_SETUP([renamed directory containing subdirectories])
+AT_KEYWORDS([incremental rename04 rename])
+
+AT_TAR_CHECK([
+AT_SORT_PREREQ
+
+decho Creating directory structure
+mkdir directory
+mkdir directory/subdir
+genfile --file=directory/file
+
+decho Creating initial archive
+tar -cf archive.1 -g db.1 directory
+
+decho Renaming
+mv directory dir
+
+decho Creating incremental archive
+cp db.1 db.2
+tar -cf archive.2 -g db.2 dir
+
+mv dir orig
+
+decho First restore
+tar -xf archive.1 -g db.1
+find directory | sort
+
+decho Second restore
+tar -xf archive.2 -g db.2
+find dir | sort
+],
+[0],
+[Creating directory structure
+Creating initial archive
+Renaming
+Creating incremental archive
+First restore
+directory
+directory/file
+directory/subdir
+Second restore
+dir
+dir/subdir
+],
+[Creating directory structure
+Creating initial archive
+Renaming
+Creating incremental archive
+First restore
+Second restore
+],[],[],[gnu, oldgnu, posix])
+
+AT_CLEANUP
+
+# End of rename04.at
+
+
--- /dev/null
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+# Description: A continuation of rename04.at, that checks additionally if
+# renamed subdirectories are restored correctly.
+
+AT_SETUP([renamed subdirectories])
+AT_KEYWORDS([incremental rename05 rename])
+
+AT_TAR_CHECK([
+AT_SORT_PREREQ
+
+decho Creating directory structure
+mkdir directory
+mkdir directory/subdir
+genfile --file=directory/file
+
+decho Creating initial archive
+tar -cf archive.1 -g db.1 directory
+
+decho Renaming
+mv directory/subdir directory/subdir.0
+mv directory dir
+
+decho Creating incremental archive
+cp db.1 db.2
+tar -cf archive.2 -g db.2 dir
+
+mv dir orig
+
+decho First restore
+tar -xf archive.1 -g db.1
+find directory | sort
+
+decho Second restore
+tar -xf archive.2 -g db.2
+find dir | sort
+],
+[0],
+[Creating directory structure
+Creating initial archive
+Renaming
+Creating incremental archive
+First restore
+directory
+directory/file
+directory/subdir
+Second restore
+dir
+dir/subdir.0
+],
+[Creating directory structure
+Creating initial archive
+Renaming
+Creating incremental archive
+First restore
+Second restore
+],[],[],[gnu, oldgnu, posix])
+
+AT_CLEANUP
+
+# End of rename05.at
+
+