The changes are based on the discussion with Nathan.
* src/common.h (normalize_filename): Take two arguments. All
callers updated.
(tar_getcwd): Replaced with ..
(tar_getcdpath): New proto.
* src/misc.c (normalize_filename): Take two arguments.
(chdir_arg): Populate cwd along with creating the
structure.
(tar_getcwd): Removed.
(tar_getcdpath): New function.
* tests/incr09.at: New test case.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Likewise.
void assign_string (char **dest, const char *src);
int unquote_string (char *str);
char *zap_slashes (char *name);
-char *normalize_filename (const char *name);
+char *normalize_filename (int cdidx, const char *name);
void normalize_filename_x (char *name);
void replace_prefix (char **pname, const char *samp, size_t slen,
const char *repl, size_t rlen);
void namebuf_add_dir (namebuf_t buf, const char *name);
char *namebuf_finish (namebuf_t buf);
-const char *tar_getcwd (void);
+const char *tar_getcdpath (int);
const char *tar_dirname (void);
/* Represent N using a signed integer I such that (uintmax_t) I == N.
static struct directory *
attach_directory (const char *name)
{
- char *cname = normalize_filename (name);
+ char *cname = normalize_filename (chdir_current, name);
struct directory *dir = make_directory (name, cname);
if (dirtail)
dirtail->next = dir;
return 0;
else
{
- char *caname = normalize_filename (name);
+ char *caname = normalize_filename (chdir_current, name);
struct directory *dir = make_directory (name, caname);
struct directory *ret = hash_lookup (directory_table, dir);
free_directory (dir);
Return a normalized newly-allocated copy. */
char *
-normalize_filename (const char *name)
+normalize_filename (int cdidx, const char *name)
{
char *copy = NULL;
getcwd is slow, it might fail, and it does not necessarily
return a canonical name even when it succeeds. Perhaps we
can use dev+ino pairs instead of names? */
- const char *cwd = tar_getcwd ();
+ const char *cwd = tar_getcdpath (cdidx);
size_t copylen;
bool need_separator;
if (! wd_count)
{
wd[wd_count].name = ".";
- wd[wd_count].cwd = NULL;
+ wd[wd_count].cwd = xgetcwd ();
wd[wd_count].fd = AT_FDCWD;
wd_count++;
}
}
wd[wd_count].name = dir;
- wd[wd_count].cwd = NULL;
+ if (IS_ABSOLUTE_FILE_NAME (wd[wd_count].name))
+ wd[wd_count].cwd = xstrdup (wd[wd_count].name);
+ else
+ {
+ namebuf_t nbuf = namebuf_create (wd[wd_count - 1].cwd);
+ namebuf_add_dir (nbuf, wd[wd_count].name);
+ wd[wd_count].cwd = namebuf_finish (nbuf);
+ }
wd[wd_count].fd = 0;
return wd_count++;
}
}
const char *
-tar_getcwd (void)
+tar_getcdpath (int idx)
{
- static char *cwd;
- namebuf_t nbuf;
- int i;
-
- if (!cwd)
- cwd = xgetcwd ();
if (!wd)
- return cwd;
-
- if (0 == chdir_current || !wd[chdir_current].cwd)
{
- if (IS_ABSOLUTE_FILE_NAME (wd[chdir_current].name))
- {
- wd[chdir_current].cwd = xstrdup (wd[chdir_current].name);
- return wd[chdir_current].cwd;
- }
- if (!wd[0].cwd)
- wd[0].cwd = cwd;
-
- for (i = chdir_current - 1; i > 0; i--)
- if (wd[i].cwd)
- break;
-
- nbuf = namebuf_create (wd[i].cwd);
- for (i++; i <= chdir_current; i++)
- namebuf_add_dir (nbuf, wd[i].name);
- wd[chdir_current].cwd = namebuf_finish (nbuf);
+ static char *cwd;
+ if (!cwd)
+ cwd = xgetcwd ();
+ return cwd;
}
- return wd[chdir_current].cwd;
+ return wd[idx].cwd;
}
\f
void
namelist = merge_sort (namelist, num_names, compare_names);
num_names = 0;
- nametab = hash_initialize (0, 0,
- name_hash,
- name_compare, NULL);
+ 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);
+ name->caname = normalize_filename (name->change_dir, name->name);
if (prev_name)
{
struct name *p = hash_lookup (nametab, name);
incr06.at\
incr07.at\
incr08.at\
+ incr09.at\
indexfile.at\
ignfail.at\
label01.at\
--- /dev/null
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+# Test suite for GNU tar.
+# Copyright 2013 Free Software Foundation, Inc.
+#
+# GNU tar 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 of the License, or
+# (at your option) any later version.
+#
+# GNU tar 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, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([incremental with alternating -C])
+AT_KEYWORDS([incremental create incr09])
+
+AT_TAR_CHECK([
+AT_SORT_PREREQ
+mkdir foo bar middle
+echo foo/foo_file > foo/foo_file
+echo bar/bar_file > bar/bar_file
+echo middle/file > middle/middle_file
+decho A
+tar -cvf foo.tar --incremental -C foo . -C `pwd` middle -C bar .
+
+rm foo.tar
+>toplevel_file
+decho B
+tar -cvf foo.tar --incremental -C foo . -C `pwd` toplevel_file -C bar .
+],
+[0],
+[A
+./
+./
+middle/
+./bar_file
+./foo_file
+middle/middle_file
+B
+./
+./
+toplevel_file
+./bar_file
+./foo_file
+],
+[A
+tar: .: Directory is new
+tar: middle: Directory is new
+tar: .: Directory is new
+B
+tar: .: Directory is new
+tar: .: Directory is new
+],[],[],[gnu])
+
+AT_CLEANUP
m4_include([incr06.at])
m4_include([incr07.at])
m4_include([incr08.at])
+m4_include([incr09.at])
AT_BANNER([Files removed while archiving])
m4_include([filerem01.at])