Take into account chdir_fd when extracting from incremental dumps.
* src/common.h (tar_savedir): New prototype. * src/misc.c (tar_savedir): New function. (remove_any_file): Use tar_savedir. * src/incremen.c (try_purge_directory): Use tar_savedir. * src/update.c (update_archive): Use tar_savedir. * tests/incr07.at: New testcase. * tests/Makefile.am (TESTSUITE_AT): Add new test. * tests/testsuite.at: Likewise. * THANKS: Updated.
This commit is contained in:
@@ -596,6 +596,7 @@ char *zap_slashes (char *name);
|
||||
char *normalize_filename (const char *name);
|
||||
void replace_prefix (char **pname, const char *samp, size_t slen,
|
||||
const char *repl, size_t rlen);
|
||||
char *tar_savedir (const char *name, int must_exist);
|
||||
|
||||
typedef struct namebuf *namebuf_t;
|
||||
namebuf_t namebuf_create (const char *dir);
|
||||
|
||||
@@ -1582,7 +1582,7 @@ try_purge_directory (char const *directory_name)
|
||||
if (!is_dumpdir (¤t_stat_info))
|
||||
return false;
|
||||
|
||||
current_dir = savedir (directory_name);
|
||||
current_dir = tar_savedir (directory_name, 0);
|
||||
|
||||
if (!current_dir)
|
||||
/* The directory doesn't exist now. It'll be created. In any
|
||||
|
||||
30
src/misc.c
30
src/misc.c
@@ -631,7 +631,7 @@ remove_any_file (const char *file_name, enum remove_option option)
|
||||
|
||||
case RECURSIVE_REMOVE_OPTION:
|
||||
{
|
||||
char *directory = savedir (file_name);
|
||||
char *directory = tar_savedir (file_name, 0);
|
||||
char const *entry;
|
||||
size_t entrylen;
|
||||
|
||||
@@ -1144,3 +1144,31 @@ namebuf_name (namebuf_t buf, const char *name)
|
||||
strcpy (buf->buffer + buf->dir_length, name);
|
||||
return buf->buffer;
|
||||
}
|
||||
|
||||
/* Return the filenames in directory NAME, relative to the chdir_fd.
|
||||
If the directory does not exist, report error if MUST_EXIST is
|
||||
true.
|
||||
|
||||
Return NULL on errors.
|
||||
*/
|
||||
char *
|
||||
tar_savedir (const char *name, int must_exist)
|
||||
{
|
||||
char *ret = NULL;
|
||||
DIR *dir = NULL;
|
||||
int fd = openat (chdir_fd, name, open_read_flags | O_DIRECTORY);
|
||||
if (fd < 0)
|
||||
{
|
||||
if (!must_exist && errno == ENOENT)
|
||||
return NULL;
|
||||
open_error (name);
|
||||
}
|
||||
else if (! ((dir = fdopendir (fd))
|
||||
&& (ret = streamsavedir (dir))))
|
||||
savedir_error (name);
|
||||
|
||||
if (dir ? closedir (dir) != 0 : 0 <= fd && close (fd) != 0)
|
||||
savedir_error (name);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
17
src/update.c
17
src/update.c
@@ -145,16 +145,8 @@ update_archive (void)
|
||||
{
|
||||
if (S_ISDIR (s.st_mode))
|
||||
{
|
||||
char *p, *dirp;
|
||||
DIR *stream = NULL;
|
||||
int fd = openat (chdir_fd, name->name,
|
||||
open_read_flags | O_DIRECTORY);
|
||||
if (fd < 0)
|
||||
open_error (name->name);
|
||||
else if (! ((stream = fdopendir (fd))
|
||||
&& (dirp = streamsavedir (stream))))
|
||||
savedir_error (name->name);
|
||||
else
|
||||
char *p, *dirp = tar_savedir (name->name, 1);
|
||||
if (dirp)
|
||||
{
|
||||
namebuf_t nbuf = namebuf_create (name->name);
|
||||
|
||||
@@ -167,11 +159,6 @@ update_archive (void)
|
||||
|
||||
remname (name);
|
||||
}
|
||||
|
||||
if (stream
|
||||
? closedir (stream) != 0
|
||||
: 0 <= fd && close (fd) != 0)
|
||||
savedir_error (name->name);
|
||||
}
|
||||
else if (tar_timespec_cmp (get_stat_mtime (&s),
|
||||
current_stat_info.mtime)
|
||||
|
||||
Reference in New Issue
Block a user