- struct stat stat_data;
- enum archive_format unused;
-
- decode_header (current_header, ¤t_stat, &unused, 0);
- if (stat (current_file_name, &stat_data) < 0)
- ERROR ((0, errno, _("Cannot stat %s"), current_file_name));
- else if (current_stat.st_mtime >= stat_data.st_mtime)
- name->found = 1;
+ struct stat s;
+
+ chdir_do (name->change_dir);
+ if (deref_stat (current_stat_info.file_name, &s) == 0)
+ {
+ 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
+ {
+ namebuf_t nbuf = namebuf_create (name->name);
+
+ for (p = dirp; *p; p += strlen (p) + 1)
+ addname (namebuf_name (nbuf, p),
+ 0, false, NULL);
+
+ namebuf_free (nbuf);
+ free (dirp);
+
+ 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)
+ <= 0)
+ remname (name);
+ }