]> Dogcows Code - chaz/tar/blobdiff - src/extract.c
Update FSF postal mail address.
[chaz/tar] / src / extract.c
index 3f4eb06ad6e75c13d1419b97b592e114bc8782f3..d193807421913e8db12dab2a4fc1f2c9edd8bf0b 100644 (file)
@@ -17,7 +17,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 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 #include <system.h>
 #include <quotearg.h>
@@ -440,7 +440,8 @@ file_newer_p (const char *file_name, struct tar_stat_info *tar_stat)
   if (stat (file_name, &st))
     {
       stat_warn (file_name);
-      return true; /* Be on the safe side */
+      /* Be on the safe side: if the file does exist assume it is newer */
+      return errno != ENOENT;
     }
   if (!S_ISDIR (st.st_mode)
       && st.st_mtime >= tar_stat->stat.st_mtime)
@@ -684,6 +685,15 @@ extract_file (char *file_name, int typeflag)
 
   if (to_stdout_option)
     fd = STDOUT_FILENO;
+  else if (to_command_option)
+    {
+      fd = sys_exec_command (file_name, 'f', &current_stat_info);
+      if (fd < 0)
+       {
+         skip_member ();
+         return 0;
+       }
+    }
   else
     {
       do
@@ -704,7 +714,7 @@ extract_file (char *file_name, int typeflag)
       {
        if (multi_volume_option)
          {
-           assign_string (&save_name, current_stat_info.file_name);
+           assign_string (&save_name, current_stat_info.orig_file_name);
            save_totsize = current_stat_info.stat.st_size;
            save_sizeleft = size;
          }
@@ -726,14 +736,15 @@ extract_file (char *file_name, int typeflag)
          written = size;
        errno = 0;
        count = full_write (fd, data_block->buffer, written);
-       size -= count;
+       size -= written;
        
        set_next_block_after ((union block *)
                              (data_block->buffer + written - 1));
        if (count != written)
          {
-           write_error_details (file_name, count, written); /* FIXME: shouldn't we
-                                                               restore from backup? */
+           if (!to_command_option)
+             write_error_details (file_name, count, written);
+           /* FIXME: shouldn't we restore from backup? */
            break;
          }
       }
@@ -753,10 +764,13 @@ extract_file (char *file_name, int typeflag)
   if (status < 0)
     close_error (file_name);
 
-  set_stat (file_name, &current_stat_info.stat, 0, 0,
-           (old_files_option == OVERWRITE_OLD_FILES ?
-                 UNKNOWN_PERMSTATUS : ARCHIVED_PERMSTATUS),
-           typeflag);
+  if (to_command_option)
+    sys_wait_command ();
+  else
+    set_stat (file_name, &current_stat_info.stat, 0, 0,
+             (old_files_option == OVERWRITE_OLD_FILES ?
+              UNKNOWN_PERMSTATUS : ARCHIVED_PERMSTATUS),
+             typeflag);
 
   return status;
 }  
@@ -976,7 +990,7 @@ prepare_to_extract (char const *file_name, int typeflag, tar_extractor_t *fun)
 {
   int rc = 1;
   
-  if (to_stdout_option)
+  if (EXTRACT_OVER_PIPE)
     rc = 0;
 
   /* Select the extractor */
@@ -1059,7 +1073,7 @@ prepare_to_extract (char const *file_name, int typeflag, tar_extractor_t *fun)
 
     default:
       WARN ((0, 0,
-            _("%s: Unknown file type '%c', extracted as normal file"),
+            _("%s: Unknown file type `%c', extracted as normal file"),
             quotearg_colon (file_name), typeflag));
       *fun = extract_file;
     }
@@ -1084,7 +1098,8 @@ prepare_to_extract (char const *file_name, int typeflag, tar_extractor_t *fun)
     case KEEP_NEWER_FILES:
       if (file_newer_p (file_name, &current_stat_info))
        {
-         WARN ((0, 0, _("Current %s is newer"), quote (file_name)));
+         WARN ((0, 0, _("Current %s is newer or same age"),
+                quote (file_name)));
          return 0;
        }
       break;
@@ -1134,7 +1149,7 @@ extract_archive (void)
 
   /* Take a safety backup of a previously existing file.  */
 
-  if (backup_option && !to_stdout_option)
+  if (backup_option)
     if (!maybe_backup_file (file_name, 0))
       {
        int e = errno;
This page took 0.023487 seconds and 4 git commands to generate.