Forráskód Böngészése

Use mv_.* functions uniformly instead of fiddling with the global variables.

Sergey Poznyakoff 19 éve
szülő
commit
52429bb956
5 módosított fájl, 54 hozzáadás és 110 törlés
  1. 12 45
      src/compare.c
  2. 17 25
      src/create.c
  3. 9 14
      src/extract.c
  4. 5 9
      src/incremen.c
  5. 11 17
      src/list.c

+ 12 - 45
src/compare.c

@@ -134,14 +134,15 @@ process_dumpdir (size_t bytes, char *buffer)
    address of the chunk it can work with.  The PROCESSOR should return
    address of the chunk it can work with.  The PROCESSOR should return
    nonzero for success.  It it return error once, continue skipping
    nonzero for success.  It it return error once, continue skipping
    without calling PROCESSOR anymore.  */
    without calling PROCESSOR anymore.  */
+
 static void
 static void
-read_and_process (off_t size, int (*processor) (size_t, char *))
+read_and_process (struct tar_stat_info *st, int (*processor) (size_t, char *))
 {
 {
   union block *data_block;
   union block *data_block;
   size_t data_size;
   size_t data_size;
-
-  if (multi_volume_option)
-    save_sizeleft = size;
+  size_t size = st->stat.st_size;
+  
+  mv_begin (st);
   while (size)
   while (size)
     {
     {
       data_block = find_next_block ();
       data_block = find_next_block ();
@@ -159,9 +160,9 @@ read_and_process (off_t size, int (*processor) (size_t, char *))
       set_next_block_after ((union block *)
       set_next_block_after ((union block *)
 			    (data_block->buffer + data_size - 1));
 			    (data_block->buffer + data_size - 1));
       size -= data_size;
       size -= data_size;
-      if (multi_volume_option)
-	save_sizeleft -= data_size;
+      mv_size_left (size);
     }
     }
+  mv_end ();
 }
 }
 
 
 /* Call either stat or lstat over STAT_DATA, depending on
 /* Call either stat or lstat over STAT_DATA, depending on
@@ -250,21 +251,7 @@ diff_file (void)
 	      if (current_stat_info.is_sparse)
 	      if (current_stat_info.is_sparse)
 		sparse_diff_file (diff_handle, &current_stat_info);
 		sparse_diff_file (diff_handle, &current_stat_info);
 	      else
 	      else
-		{
-		  if (multi_volume_option)
-		    {
-		      assign_string (&save_name,
-                                     current_stat_info.orig_file_name);
-		      save_totsize = current_stat_info.stat.st_size;
-		      /* save_sizeleft is set in read_and_process.  */
-		    }
-
-		  read_and_process (current_stat_info.stat.st_size,
-				    process_rawdata);
-
-		  if (multi_volume_option)
-		    assign_string (&save_name, 0);
-		}
+		read_and_process (&current_stat_info, process_rawdata);
 
 
 	      status = close (diff_handle);
 	      status = close (diff_handle);
 	      if (status != 0)
 	      if (status != 0)
@@ -373,24 +360,14 @@ diff_dumpdir (void)
       
       
   dumpdir_buffer = get_directory_contents (current_stat_info.file_name, dev);
   dumpdir_buffer = get_directory_contents (current_stat_info.file_name, dev);
 
 
-  if (multi_volume_option)
-    {
-      assign_string (&save_name, current_stat_info.orig_file_name);
-      save_totsize = current_stat_info.stat.st_size;
-      /* save_sizeleft is set in read_and_process.  */
-    }
-
   if (dumpdir_buffer)
   if (dumpdir_buffer)
     {
     {
       dumpdir_cursor = dumpdir_buffer;
       dumpdir_cursor = dumpdir_buffer;
-      read_and_process (current_stat_info.stat.st_size, process_dumpdir);
+      read_and_process (&current_stat_info, process_dumpdir);
       free (dumpdir_buffer);
       free (dumpdir_buffer);
     }
     }
   else
   else
-    read_and_process (current_stat_info.stat.st_size, process_noop);
-
-  if (multi_volume_option)
-    assign_string (&save_name, 0);
+    read_and_process (&current_stat_info, process_noop);
 }
 }
 
 
 static void
 static void
@@ -441,18 +418,8 @@ diff_multivol (void)
       return;
       return;
     }
     }
 
 
-  if (multi_volume_option)
-    {
-      assign_string (&save_name, current_stat_info.orig_file_name);
-      save_totsize = stat_data.st_size;
-      /* save_sizeleft is set in read_and_process.  */
-    }
-
-  read_and_process (current_stat_info.stat.st_size, process_rawdata);
-
-  if (multi_volume_option)
-    assign_string (&save_name, 0);
-
+  read_and_process (&current_stat_info, process_rawdata);
+  
   status = close (fd);
   status = close (fd);
   if (status != 0)
   if (status != 0)
     close_error (current_stat_info.file_name);
     close_error (current_stat_info.file_name);

+ 17 - 25
src/create.c

@@ -452,7 +452,7 @@ write_gnu_long_link (struct tar_stat_info *st, const char *p, char type)
   finish_header (st, header, -1);
   finish_header (st, header, -1);
 
 
   header = find_next_block ();
   header = find_next_block ();
-
+  
   bufsize = available_space_after (header);
   bufsize = available_space_after (header);
 
 
   while (bufsize < size)
   while (bufsize < size)
@@ -576,8 +576,8 @@ write_long_name (struct tar_stat_info *st)
   return write_short_name (st);
   return write_short_name (st);
 }
 }
 
 
-static union block *
-write_extended (struct tar_stat_info *st, union block *old_header)
+union block *
+write_extended (char type, struct tar_stat_info *st, union block *old_header)
 {
 {
   union block *header, hp;
   union block *header, hp;
   char *p;
   char *p;
@@ -588,7 +588,7 @@ write_extended (struct tar_stat_info *st, union block *old_header)
   xheader_finish (&extended_header);
   xheader_finish (&extended_header);
   memcpy (hp.buffer, old_header, sizeof (hp));
   memcpy (hp.buffer, old_header, sizeof (hp));
   p = xheader_xhdr_name (st);
   p = xheader_xhdr_name (st);
-  xheader_write (XHDTYPE, p, &extended_header);
+  xheader_write (type, p, &extended_header);
   free (p);
   free (p);
   header = find_next_block ();
   header = find_next_block ();
   memcpy (header, &hp.buffer, sizeof (hp.buffer));
   memcpy (header, &hp.buffer, sizeof (hp.buffer));
@@ -852,7 +852,7 @@ finish_header (struct tar_stat_info *st,
       print_header (st, block_ordinal);
       print_header (st, block_ordinal);
     }
     }
 
 
-  header = write_extended (st, header);
+  header = write_extended (XHDTYPE, st, header);
   simple_finish_header (header);
   simple_finish_header (header);
 }
 }
 
 
@@ -863,7 +863,7 @@ pad_archive (off_t size_left)
   union block *blk;
   union block *blk;
   while (size_left > 0)
   while (size_left > 0)
     {
     {
-      save_sizeleft = size_left;
+      mv_size_left (size_left);
       blk = find_next_block ();
       blk = find_next_block ();
       memset (blk->buffer, 0, BLOCKSIZE);
       memset (blk->buffer, 0, BLOCKSIZE);
       set_next_block_after (blk);
       set_next_block_after (blk);
@@ -889,16 +889,13 @@ dump_regular_file (int fd, struct tar_stat_info *st)
 
 
   finish_header (st, blk, block_ordinal);
   finish_header (st, blk, block_ordinal);
 
 
+  mv_begin (st);
   while (size_left > 0)
   while (size_left > 0)
     {
     {
       size_t bufsize, count;
       size_t bufsize, count;
 
 
-      if (multi_volume_option)
-	{
-	  assign_string (&save_name, st->orig_file_name);
-	  save_sizeleft = size_left;
-	  save_totsize = st->stat.st_size;
-	}
+      mv_size_left (size_left);
+
       blk = find_next_block ();
       blk = find_next_block ();
 
 
       bufsize = available_space_after (blk);
       bufsize = available_space_after (blk);
@@ -1054,7 +1051,7 @@ dump_dir0 (char *directory,
 	      const char *buffer, *p_buffer;
 	      const char *buffer, *p_buffer;
 	      
 	      
 	      block_ordinal = current_block_ordinal ();
 	      block_ordinal = current_block_ordinal ();
-	      buffer = gnu_list_name->dir_contents; /* FOO */
+	      buffer = gnu_list_name->dir_contents; 
 	      if (buffer)
 	      if (buffer)
 		totsize = dumpdir_size (buffer);
 		totsize = dumpdir_size (buffer);
 	      else
 	      else
@@ -1063,14 +1060,12 @@ dump_dir0 (char *directory,
 	      finish_header (st, blk, block_ordinal);
 	      finish_header (st, blk, block_ordinal);
 	      p_buffer = buffer;
 	      p_buffer = buffer;
 	      size_left = totsize;
 	      size_left = totsize;
+	      
+	      mv_begin (st);
+	      mv_total_size (totsize);
 	      while (size_left > 0)
 	      while (size_left > 0)
 		{
 		{
-		  if (multi_volume_option)
-		    {
-		      assign_string (&save_name, st->orig_file_name);
-		      save_sizeleft = size_left;
-		      save_totsize = totsize;
-		    }
+		  mv_size_left (size_left);
 		  blk = find_next_block ();
 		  blk = find_next_block ();
 		  bufsize = available_space_after (blk);
 		  bufsize = available_space_after (blk);
 		  if (size_left < bufsize)
 		  if (size_left < bufsize)
@@ -1085,8 +1080,7 @@ dump_dir0 (char *directory,
 		  p_buffer += bufsize;
 		  p_buffer += bufsize;
 		  set_next_block_after (blk + (bufsize - 1) / BLOCKSIZE);
 		  set_next_block_after (blk + (bufsize - 1) / BLOCKSIZE);
 		}
 		}
-	      if (multi_volume_option)
-		assign_string (&save_name, 0);
+	      mv_end ();
 	    }
 	    }
 	  return;
 	  return;
 	}
 	}
@@ -1504,14 +1498,12 @@ dump_file0 (struct tar_stat_info *st, char *p,
 	  switch (status)
 	  switch (status)
 	    {
 	    {
 	    case dump_status_ok:
 	    case dump_status_ok:
-	      if (multi_volume_option)
-		assign_string (&save_name, 0);
+	      mv_end ();
 	      dump_regular_finish (fd, st, original_ctime);
 	      dump_regular_finish (fd, st, original_ctime);
 	      break;
 	      break;
 
 
 	    case dump_status_short:
 	    case dump_status_short:
-	      if (multi_volume_option)
-		assign_string (&save_name, 0);
+	      mv_end ();
 	      close (fd);
 	      close (fd);
 	      break;
 	      break;
 
 

+ 9 - 14
src/extract.c

@@ -739,37 +739,33 @@ extract_file (char *file_name, int typeflag)
 	}
 	}
     }
     }
 
 
+  mv_begin (&current_stat_info);
   if (current_stat_info.is_sparse)
   if (current_stat_info.is_sparse)
     sparse_extract_file (fd, &current_stat_info, &size);
     sparse_extract_file (fd, &current_stat_info, &size);
   else
   else
     for (size = current_stat_info.stat.st_size; size > 0; )
     for (size = current_stat_info.stat.st_size; size > 0; )
       {
       {
-	if (multi_volume_option)
-	  {
-	    assign_string (&save_name, current_stat_info.orig_file_name);
-	    save_totsize = current_stat_info.stat.st_size;
-	    save_sizeleft = size;
-	  }
-
+	mv_size_left (size);
+	
 	/* Locate data, determine max length writeable, write it,
 	/* Locate data, determine max length writeable, write it,
 	   block that we have used the data, then check if the write
 	   block that we have used the data, then check if the write
 	   worked.  */
 	   worked.  */
-
+	
 	data_block = find_next_block ();
 	data_block = find_next_block ();
 	if (! data_block)
 	if (! data_block)
 	  {
 	  {
 	    ERROR ((0, 0, _("Unexpected EOF in archive")));
 	    ERROR ((0, 0, _("Unexpected EOF in archive")));
 	    break;		/* FIXME: What happens, then?  */
 	    break;		/* FIXME: What happens, then?  */
 	  }
 	  }
-
+	
 	written = available_space_after (data_block);
 	written = available_space_after (data_block);
-
+	
 	if (written > size)
 	if (written > size)
 	  written = size;
 	  written = size;
 	errno = 0;
 	errno = 0;
 	count = full_write (fd, data_block->buffer, written);
 	count = full_write (fd, data_block->buffer, written);
 	size -= written;
 	size -= written;
-
+	
 	set_next_block_after ((union block *)
 	set_next_block_after ((union block *)
 			      (data_block->buffer + written - 1));
 			      (data_block->buffer + written - 1));
 	if (count != written)
 	if (count != written)
@@ -783,9 +779,8 @@ extract_file (char *file_name, int typeflag)
 
 
   skip_file (size);
   skip_file (size);
 
 
-  if (multi_volume_option)
-    assign_string (&save_name, 0);
-
+  mv_end ();
+  
   /* If writing to stdout, don't try to do anything to the filename;
   /* If writing to stdout, don't try to do anything to the filename;
      it doesn't exist, or we don't want to touch it anyway.  */
      it doesn't exist, or we don't want to touch it anyway.  */
 
 

+ 5 - 9
src/incremen.c

@@ -648,15 +648,11 @@ get_gnu_dumpdir ()
   to = archive_dir;
   to = archive_dir;
 
 
   set_next_block_after (current_header);
   set_next_block_after (current_header);
-  if (multi_volume_option)
-    {
-      assign_string (&save_name, current_stat_info.orig_file_name);
-      save_totsize = current_stat_info.stat.st_size;
-    }
+  mv_begin (&current_stat_info);
+
   for (; size > 0; size -= copied)
   for (; size > 0; size -= copied)
     {
     {
-      if (multi_volume_option)
-	save_sizeleft = size;
+      mv_size_left (size);
       data_block = find_next_block ();
       data_block = find_next_block ();
       if (!data_block)
       if (!data_block)
 	ERROR ((1, 0, _("Unexpected EOF in archive")));
 	ERROR ((1, 0, _("Unexpected EOF in archive")));
@@ -668,8 +664,8 @@ get_gnu_dumpdir ()
       set_next_block_after ((union block *)
       set_next_block_after ((union block *)
 			    (data_block->buffer + copied - 1));
 			    (data_block->buffer + copied - 1));
     }
     }
-  if (multi_volume_option)
-    assign_string (&save_name, 0);
+
+  mv_end ();
   
   
   current_stat_info.stat.st_size = 0; /* For skip_member() and friends
   current_stat_info.stat.st_size = 0; /* For skip_member() and friends
 					 to work correctly */
 					 to work correctly */

+ 11 - 17
src/list.c

@@ -222,13 +222,11 @@ list_archive (void)
 	}
 	}
     }
     }
 
 
-  if (multi_volume_option)
-    assign_string (&save_name, current_stat_info.orig_file_name);
+  mv_begin (&current_stat_info);
 
 
   skip_member ();
   skip_member ();
 
 
-  if (multi_volume_option)
-    assign_string (&save_name, 0);
+  mv_end ();
 }
 }
 
 
 /* Check header checksum */
 /* Check header checksum */
@@ -400,6 +398,7 @@ read_header (bool raw_extended_headers)
 	    {
 	    {
 	      xheader_read (header, OFF_FROM_HEADER (header->header.size));
 	      xheader_read (header, OFF_FROM_HEADER (header->header.size));
 	      xheader_decode_global ();
 	      xheader_decode_global ();
+	      xheader_destroy (&extended_header);
 	    }
 	    }
 
 
 	  /* Loop!  */
 	  /* Loop!  */
@@ -1269,25 +1268,19 @@ skip_file (off_t size)
 {
 {
   union block *x;
   union block *x;
 
 
-  if (multi_volume_option)
-    {
-      save_totsize = size;
-      save_sizeleft = size;
-    }
+  /* FIXME: Make sure mv_begin is always called before it */
 
 
   if (seekable_archive)
   if (seekable_archive)
     {
     {
       off_t nblk = seek_archive (size);
       off_t nblk = seek_archive (size);
       if (nblk >= 0)
       if (nblk >= 0)
-	{
-	  size -= nblk * BLOCKSIZE;
-	  if (multi_volume_option) /* Argh.. */
-	    save_sizeleft -= nblk * BLOCKSIZE;
-	}
+	size -= nblk * BLOCKSIZE;
       else
       else
 	seekable_archive = false;
 	seekable_archive = false;
     }
     }
 
 
+  mv_size_left (size);
+  
   while (size > 0)
   while (size > 0)
     {
     {
       x = find_next_block ();
       x = find_next_block ();
@@ -1296,8 +1289,7 @@ skip_file (off_t size)
 
 
       set_next_block_after (x);
       set_next_block_after (x);
       size -= BLOCKSIZE;
       size -= BLOCKSIZE;
-      if (multi_volume_option)
-	save_sizeleft -= BLOCKSIZE;
+      mv_size_left (size);
     }
     }
 }
 }
 
 
@@ -1309,10 +1301,12 @@ skip_member (void)
   char save_typeflag = current_header->header.typeflag;
   char save_typeflag = current_header->header.typeflag;
   set_next_block_after (current_header);
   set_next_block_after (current_header);
 
 
-  assign_string (&save_name, current_stat_info.orig_file_name);
+  mv_begin (&current_stat_info);
 
 
   if (current_stat_info.is_sparse)
   if (current_stat_info.is_sparse)
     sparse_skip_file (&current_stat_info);
     sparse_skip_file (&current_stat_info);
   else if (save_typeflag != DIRTYPE)
   else if (save_typeflag != DIRTYPE)
     skip_file (current_stat_info.stat.st_size);
     skip_file (current_stat_info.stat.st_size);
+
+  mv_end ();
 }
 }