+
+ /* See if we want only new files, and check if this one is too old to
+ put in the archive. */
+
+ if ((0 < top_level || !incremental_option)
+ && !S_ISDIR (current_stat.st_mode)
+ && current_stat.st_mtime < newer_mtime_option
+ && (!after_date_option || current_stat.st_ctime < newer_ctime_option))
+ {
+ if (0 < top_level)
+ WARN ((0, 0, _("%s: is unchanged; not dumped"), p));
+ /* FIXME: recheck this return. */
+ return;
+ }
+
+#if !MSDOS
+ /* See if we are trying to dump the archive. */
+
+ if (ar_dev && current_stat.st_dev == ar_dev && current_stat.st_ino == ar_ino)
+ {
+ WARN ((0, 0, _("%s is the archive; not dumped"), p));
+ return;
+ }
+#endif
+
+ if (S_ISDIR (current_stat.st_mode))
+ {
+ DIR *directory;
+ struct dirent *entry;
+ char *namebuf;
+ size_t buflen;
+ size_t len;
+ dev_t our_device = current_stat.st_dev;
+
+ /* If this tar program is installed suid root, like for Amanda, the
+ access might look like denied, while it is not really.
+
+ FIXME: I have the feeling this test is done too early. Couldn't it
+ just be bundled in later actions? I guess that the proper support
+ of --ignore-failed-read is the key of the current writing. */
+
+ if (access (p, R_OK) == -1 && geteuid () != 0)
+ {
+ WARN ((0, errno, _("Cannot add directory %s"), p));
+ if (!ignore_failed_read_option)
+ exit_status = TAREXIT_FAILURE;
+ return;
+ }
+
+ /* Build new prototype name. Ensure exactly one trailing slash. */
+
+ len = strlen (p);
+ buflen = len + NAME_FIELD_SIZE;
+ namebuf = xmalloc (buflen + 1);
+ strncpy (namebuf, p, buflen);
+ while (len >= 1 && namebuf[len - 1] == '/')
+ len--;
+ namebuf[len++] = '/';
+ namebuf[len] = '\0';
+
+ if (! is_avoided_name (namebuf))
+ {
+ /* The condition above used to be "archive_format != V7_FORMAT".
+ GNU tar was not writing directory blocks at all. Daniel Trinkle
+ writes: ``All old versions of tar I have ever seen have
+ correctly archived an empty directory. The really old ones I
+ checked included HP-UX 7 and Mt. Xinu More/BSD. There may be
+ some subtle reason for the exclusion that I don't know, but the
+ current behavior is broken.'' I do not know those subtle
+ reasons either, so until these are reported (anew?), just allow
+ directory blocks to be written even with old archives. */
+
+ current_stat.st_size = 0; /* force 0 size on dir */
+
+ /* FIXME: If people could really read standard archives, this
+ should be:
+
+ header
+ = start_header (standard_option ? p : namebuf, ¤t_stat);
+
+ but since they'd interpret DIRTYPE blocks as regular
+ files, we'd better put the / on the name. */
+
+ header = start_header (namebuf, ¤t_stat);
+
+ if (incremental_option)
+ header->header.typeflag = GNUTYPE_DUMPDIR;
+ else /* if (standard_option) */
+ header->header.typeflag = DIRTYPE;
+
+ /* If we're gnudumping, we aren't done yet so don't close it. */
+
+ if (!incremental_option)
+ finish_header (header); /* done with directory header */
+ }
+
+ if (incremental_option && gnu_list_name->dir_contents)
+ {
+ off_t sizeleft;
+ off_t totsize;
+ size_t bufsize;
+ union block *start;
+ ssize_t count;
+ const char *buffer, *p_buffer;
+
+ buffer = gnu_list_name->dir_contents; /* FOO */
+ totsize = 0;
+ for (p_buffer = buffer; p_buffer && *p_buffer;)
+ {
+ size_t tmp;
+
+ tmp = strlen (p_buffer) + 1;
+ totsize += tmp;
+ p_buffer += tmp;
+ }
+ totsize++;
+ OFF_TO_CHARS (totsize, header->header.size);
+ finish_header (header);
+ p_buffer = buffer;
+ sizeleft = totsize;
+ while (sizeleft > 0)
+ {
+ if (multi_volume_option)
+ {
+ assign_string (&save_name, p);
+ save_sizeleft = sizeleft;
+ save_totsize = totsize;
+ }
+ start = find_next_block ();
+ bufsize = available_space_after (start);
+ if (sizeleft < bufsize)
+ {
+ bufsize = sizeleft;
+ count = bufsize % BLOCKSIZE;
+ if (count)
+ memset (start->buffer + sizeleft, 0, BLOCKSIZE - count);