address of the chunk it can work with. The PROCESSOR should return
nonzero for success. It it return error once, continue skipping
without calling PROCESSOR anymore. */
+
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;
size_t data_size;
-
- if (multi_volume_option)
- save_sizeleft = size;
+ size_t size = st->stat.st_size;
+
+ mv_begin (st);
while (size)
{
data_block = find_next_block ();
set_next_block_after ((union block *)
(data_block->buffer + data_size - 1));
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
if (current_stat_info.is_sparse)
sparse_diff_file (diff_handle, ¤t_stat_info);
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 (¤t_stat_info, process_rawdata);
status = close (diff_handle);
if (status != 0)
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)
{
dumpdir_cursor = dumpdir_buffer;
- read_and_process (current_stat_info.stat.st_size, process_dumpdir);
+ read_and_process (¤t_stat_info, process_dumpdir);
free (dumpdir_buffer);
}
else
- read_and_process (current_stat_info.stat.st_size, process_noop);
-
- if (multi_volume_option)
- assign_string (&save_name, 0);
+ read_and_process (¤t_stat_info, process_noop);
}
static void
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 (¤t_stat_info, process_rawdata);
+
status = close (fd);
if (status != 0)
close_error (current_stat_info.file_name);
finish_header (st, header, -1);
header = find_next_block ();
-
+
bufsize = available_space_after (header);
while (bufsize < size)
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;
char *p;
xheader_finish (&extended_header);
memcpy (hp.buffer, old_header, sizeof (hp));
p = xheader_xhdr_name (st);
- xheader_write (XHDTYPE, p, &extended_header);
+ xheader_write (type, p, &extended_header);
free (p);
header = find_next_block ();
memcpy (header, &hp.buffer, sizeof (hp.buffer));
print_header (st, block_ordinal);
}
- header = write_extended (st, header);
+ header = write_extended (XHDTYPE, st, header);
simple_finish_header (header);
}
\f
union block *blk;
while (size_left > 0)
{
- save_sizeleft = size_left;
+ mv_size_left (size_left);
blk = find_next_block ();
memset (blk->buffer, 0, BLOCKSIZE);
set_next_block_after (blk);
finish_header (st, blk, block_ordinal);
+ mv_begin (st);
while (size_left > 0)
{
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 ();
bufsize = available_space_after (blk);
const char *buffer, *p_buffer;
block_ordinal = current_block_ordinal ();
- buffer = gnu_list_name->dir_contents; /* FOO */
+ buffer = gnu_list_name->dir_contents;
if (buffer)
totsize = dumpdir_size (buffer);
else
finish_header (st, blk, block_ordinal);
p_buffer = buffer;
size_left = totsize;
+
+ mv_begin (st);
+ mv_total_size (totsize);
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 ();
bufsize = available_space_after (blk);
if (size_left < bufsize)
p_buffer += bufsize;
set_next_block_after (blk + (bufsize - 1) / BLOCKSIZE);
}
- if (multi_volume_option)
- assign_string (&save_name, 0);
+ mv_end ();
}
return;
}
switch (status)
{
case dump_status_ok:
- if (multi_volume_option)
- assign_string (&save_name, 0);
+ mv_end ();
dump_regular_finish (fd, st, original_ctime);
break;
case dump_status_short:
- if (multi_volume_option)
- assign_string (&save_name, 0);
+ mv_end ();
close (fd);
break;
}
}
+ mv_begin (¤t_stat_info);
if (current_stat_info.is_sparse)
sparse_extract_file (fd, ¤t_stat_info, &size);
else
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,
block that we have used the data, then check if the write
worked. */
-
+
data_block = find_next_block ();
if (! data_block)
{
ERROR ((0, 0, _("Unexpected EOF in archive")));
break; /* FIXME: What happens, then? */
}
-
+
written = available_space_after (data_block);
-
+
if (written > size)
written = size;
errno = 0;
count = full_write (fd, data_block->buffer, written);
size -= written;
-
+
set_next_block_after ((union block *)
(data_block->buffer + written - 1));
if (count != written)
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;
it doesn't exist, or we don't want to touch it anyway. */
to = archive_dir;
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 (¤t_stat_info);
+
for (; size > 0; size -= copied)
{
- if (multi_volume_option)
- save_sizeleft = size;
+ mv_size_left (size);
data_block = find_next_block ();
if (!data_block)
ERROR ((1, 0, _("Unexpected EOF in archive")));
set_next_block_after ((union block *)
(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
to work correctly */
}
}
- if (multi_volume_option)
- assign_string (&save_name, current_stat_info.orig_file_name);
+ mv_begin (¤t_stat_info);
skip_member ();
- if (multi_volume_option)
- assign_string (&save_name, 0);
+ mv_end ();
}
/* Check header checksum */
{
xheader_read (header, OFF_FROM_HEADER (header->header.size));
xheader_decode_global ();
+ xheader_destroy (&extended_header);
}
/* Loop! */
{
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)
{
off_t nblk = seek_archive (size);
if (nblk >= 0)
- {
- size -= nblk * BLOCKSIZE;
- if (multi_volume_option) /* Argh.. */
- save_sizeleft -= nblk * BLOCKSIZE;
- }
+ size -= nblk * BLOCKSIZE;
else
seekable_archive = false;
}
+ mv_size_left (size);
+
while (size > 0)
{
x = find_next_block ();
set_next_block_after (x);
size -= BLOCKSIZE;
- if (multi_volume_option)
- save_sizeleft -= BLOCKSIZE;
+ mv_size_left (size);
}
}
char save_typeflag = current_header->header.typeflag;
set_next_block_after (current_header);
- assign_string (&save_name, current_stat_info.orig_file_name);
+ mv_begin (¤t_stat_info);
if (current_stat_info.is_sparse)
sparse_skip_file (¤t_stat_info);
else if (save_typeflag != DIRTYPE)
skip_file (current_stat_info.stat.st_size);
+
+ mv_end ();
}