]> Dogcows Code - chaz/tar/blobdiff - src/buffer.c
Allow installers to specify alternative program names for compression programs.
[chaz/tar] / src / buffer.c
index 5f5457a95571e531a027179b511fdb0c41763d69..d7ff214f604070cbec9087d672b695823506b668 100644 (file)
@@ -1,7 +1,7 @@
 /* Buffer management for tar.
 
    Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001,
-   2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
    Written by John Gilmore, on 1985-08-25.
 
@@ -204,7 +204,8 @@ enum compress_type {
   ct_gzip,
   ct_bzip2,
   ct_lzma,
-  ct_lzop
+  ct_lzop,
+  ct_xz
 };
 
 struct zip_magic
@@ -219,11 +220,12 @@ struct zip_magic
 static struct zip_magic const magic[] = {
   { ct_tar },
   { ct_none, },
-  { ct_compress, 2, "\037\235", "compress", "-Z" },
-  { ct_gzip,     2, "\037\213", "gzip", "-z"  },
-  { ct_bzip2,    3, "BZh",      "bzip2", "-j" },
-  { ct_lzma,     6, "\xFFLZMA", "lzma", "-J" }, /* FIXME: ???? */
-  { ct_lzop,     4, "\211LZO",  "lzop", "--lzop" },
+  { ct_compress, 2, "\037\235",  COMPRESS_PROGRAM, "-Z" },
+  { ct_gzip,     2, "\037\213",  GZIP_PROGRAM,     "-z"  },
+  { ct_bzip2,    3, "BZh",       BZIP2_PROGRAM,    "-j" },
+  { ct_lzma,     6, "\xFFLZMA",  LZMA_PROGRAM,     "--lzma" },
+  { ct_lzop,     4, "\211LZO",   LZOP_PROGRAM,     "--lzop" },
+  { ct_xz,       6, "\0xFD7zXZ", XZ_PROGRAM,       "-J" },
 };
 
 #define NMAGIC (sizeof(magic)/sizeof(magic[0]))
@@ -263,6 +265,37 @@ check_compressed_archive (bool *pshort)
   return ct_none;
 }
 
+/* Guess if the archive is seekable. */
+static void
+guess_seekable_archive ()
+{
+  struct stat st;
+
+  if (subcommand_option == DELETE_SUBCOMMAND)
+    {
+      /* The current code in delete.c is based on the assumption that
+        skip_member() reads all data from the archive. So, we should
+        make sure it won't use seeks. On the other hand, the same code
+        depends on the ability to backspace a record in the archive,
+        so setting seekable_archive to false is technically incorrect.
+         However, it is tested only in skip_member(), so it's not a
+        problem. */
+      seekable_archive = false;
+    }
+
+  if (seek_option != -1)
+    {
+      seekable_archive = !!seek_option;
+      return;
+    }
+  
+  if (!multi_volume_option && !use_compress_program_option
+      && fstat (archive, &st) == 0)
+    seekable_archive = S_ISREG (st.st_mode);
+  else
+    seekable_archive = false;
+}
+
 /* Open an archive named archive_name_array[0]. Detect if it is
    a compressed archive of known type and use corresponding decompression
    program if so */
@@ -293,7 +326,7 @@ open_compressed_archive ()
                 ERROR ((0, 0, _("This does not look like a tar archive")));
               set_comression_program_by_suffix (archive_name_array[0], NULL);
               if (!use_compress_program_option)
-                return archive;
+               return archive;
               break;
 
             default:
@@ -304,7 +337,7 @@ open_compressed_archive ()
       
       /* FD is not needed any more */
       rmtclose (archive);
-
+      
       hit_eof = false; /* It might have been set by find_next_block in
                           check_compressed_archive */
 
@@ -563,6 +596,7 @@ _open_archive (enum access_mode wanted_access)
       {
       case ACCESS_READ:
         archive = open_compressed_archive ();
+       guess_seekable_archive ();
         break;
 
       case ACCESS_WRITE:
@@ -677,6 +711,19 @@ archive_read_error (void)
   return;
 }
 
+static bool
+archive_is_dev ()
+{
+  struct stat st;
+
+  if (fstat (archive, &st))
+    {
+      stat_diag (*archive_name_cursor);
+      return false;
+    }
+  return S_ISBLK (st.st_mode) || S_ISCHR (st.st_mode);
+}
+
 static void
 short_read (size_t status)
 {
@@ -688,7 +735,8 @@ short_read (size_t status)
 
   if (left && left % BLOCKSIZE == 0
       && verbose_option
-      && record_start_block == 0 && status != 0)
+      && record_start_block == 0 && status != 0
+      && archive_is_dev ())
     {
       unsigned long rsize = status / BLOCKSIZE;
       WARN ((0, 0,
@@ -1082,6 +1130,7 @@ new_volume (enum access_mode mode)
       case ACCESS_READ:
         archive = rmtopen (*archive_name_cursor, O_RDONLY, MODE_RW,
                            rsh_command_option);
+       guess_seekable_archive ();
         break;
 
       case ACCESS_WRITE:
This page took 0.024293 seconds and 4 git commands to generate.