]> Dogcows Code - chaz/tar/blobdiff - src/update.c
(update_archive): excluded_pathname -> excluded_name.
[chaz/tar] / src / update.c
index a78b9775e168a2f23e196e6eeabf08f8ae86e2ba..05c68f3e317838ade05e3cd045059244e4ea10e6 100644 (file)
@@ -13,7 +13,7 @@
 
    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
-   59 Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 /* Implement the 'r', 'u' and 'A' options for tar.  'A' means that the
    file names are tar files, and they should simply be appended to the end
@@ -45,46 +45,52 @@ char *output_start;
 static void
 append_file (char *path)
 {
-  int handle;
+  int handle = open (path, O_RDONLY | O_BINARY);
   struct stat stat_data;
-  long bytes_left;
 
-  if (stat (path, &stat_data) != 0
-      || (handle = open (path, O_RDONLY | O_BINARY), handle < 0))
+  if (handle < 0)
     {
       ERROR ((0, errno, _("Cannot open file %s"), path));
       return;
     }
 
-  bytes_left = stat_data.st_size;
-
-  while (bytes_left > 0)
+  if (fstat (handle, &stat_data) != 0)
+    ERROR ((0, errno, "%s", path));
+  else
     {
-      union block *start = find_next_block ();
-      long buffer_size = available_space_after (start);
-      int status;
+      off_t bytes_left = stat_data.st_size;
 
-      if (bytes_left < buffer_size)
+      while (bytes_left > 0)
        {
-         buffer_size = bytes_left;
-         status = buffer_size % BLOCKSIZE;
-         if (status)
-           memset (start->buffer + bytes_left, 0,
-                   (size_t) (BLOCKSIZE - status));
-       }
+         union block *start = find_next_block ();
+         size_t buffer_size = available_space_after (start);
+         ssize_t status;
+         char buf[UINTMAX_STRSIZE_BOUND];
 
-      status = read (handle, start->buffer, (size_t) buffer_size);
-      if (status < 0)
-       FATAL_ERROR ((0, errno,
-               _("Read error at byte %ld reading %d bytes in file %s"),
-               stat_data.st_size - bytes_left, buffer_size, path));
-      bytes_left -= status;
+         if (bytes_left < buffer_size)
+           {
+             buffer_size = bytes_left;
+             status = buffer_size % BLOCKSIZE;
+             if (status)
+               memset (start->buffer + bytes_left, 0,
+                       (size_t) (BLOCKSIZE - status));
+           }
 
-      set_next_block_after (start + (status - 1) / BLOCKSIZE);
+         status = safe_read (handle, start->buffer, buffer_size);
+         if (status < 0)
+           FATAL_ERROR ((0, errno,
+                         _("Read error at byte %s reading %lu bytes in file %s"),
+                         STRINGIFY_BIGINT (stat_data.st_size - bytes_left,
+                                           buf),
+                         (unsigned long) buffer_size, path));
+         if (status == 0)
+           FATAL_ERROR ((0, 0, _("%s: File shrunk by %s bytes, (yark!)"),
+                         path, STRINGIFY_BIGINT (bytes_left, buf)));
 
-      if (status != buffer_size)
-       FATAL_ERROR ((0, 0, _("%s: File shrunk by %d bytes, (yark!)"),
-                     path, bytes_left));
+         bytes_left -= status;
+
+         set_next_block_after (start + (status - 1) / BLOCKSIZE);
+       }
     }
 
   close (handle);
@@ -135,7 +141,7 @@ update_archive (void)
            set_next_block_after (current_header);
            if (current_header->oldgnu_header.isextended)
              skip_extended_headers ();
-           skip_file ((long) current_stat.st_size);
+           skip_file (current_stat.st_size);
            break;
          }
 
@@ -182,12 +188,14 @@ update_archive (void)
 
     while (path = name_from_list (), path)
       {
+       if (excluded_name (path))
+         continue;
        if (interactive_option && !confirm ("add", path))
          continue;
        if (subcommand_option == CAT_SUBCOMMAND)
          append_file (path);
        else
-         dump_file (path, -1, 1);
+         dump_file (path, (dev_t) -1, 1);
       }
   }
 
This page took 0.023628 seconds and 4 git commands to generate.