- if (deref_stat (dereference_option,
- current_stat_info.file_name, &s) == 0
- && s.st_mtime <= current_stat_info.stat.st_mtime)
- add_avoided_name (current_stat_info.file_name);
+ 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);
+ }