From: Sergey Poznyakoff Date: Wed, 9 Nov 2005 13:08:42 +0000 (+0000) Subject: Use mv_.* functions uniformly instead of fiddling with the global variables. X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Ftar;a=commitdiff_plain;h=52429bb9563d5b4bfece4cf9036ce9363e05996b Use mv_.* functions uniformly instead of fiddling with the global variables. --- diff --git a/src/compare.c b/src/compare.c index 0173363..cdbf945 100644 --- a/src/compare.c +++ b/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 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 (); @@ -159,9 +160,9 @@ read_and_process (off_t size, int (*processor) (size_t, char *)) 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 @@ -250,21 +251,7 @@ diff_file (void) 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) @@ -373,24 +360,14 @@ diff_dumpdir (void) 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 @@ -441,18 +418,8 @@ diff_multivol (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); diff --git a/src/create.c b/src/create.c index 645bcb6..6f553fe 100644 --- a/src/create.c +++ b/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); header = find_next_block (); - + bufsize = available_space_after (header); while (bufsize < size) @@ -576,8 +576,8 @@ write_long_name (struct tar_stat_info *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; char *p; @@ -588,7 +588,7 @@ write_extended (struct tar_stat_info *st, union block *old_header) 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)); @@ -852,7 +852,7 @@ finish_header (struct tar_stat_info *st, print_header (st, block_ordinal); } - header = write_extended (st, header); + header = write_extended (XHDTYPE, st, header); simple_finish_header (header); } @@ -863,7 +863,7 @@ pad_archive (off_t size_left) 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); @@ -889,16 +889,13 @@ dump_regular_file (int fd, struct tar_stat_info *st) 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); @@ -1054,7 +1051,7 @@ dump_dir0 (char *directory, 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 @@ -1063,14 +1060,12 @@ dump_dir0 (char *directory, 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) @@ -1085,8 +1080,7 @@ dump_dir0 (char *directory, p_buffer += bufsize; set_next_block_after (blk + (bufsize - 1) / BLOCKSIZE); } - if (multi_volume_option) - assign_string (&save_name, 0); + mv_end (); } return; } @@ -1504,14 +1498,12 @@ dump_file0 (struct tar_stat_info *st, char *p, 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; diff --git a/src/extract.c b/src/extract.c index fbb93ed..3ef7f28 100644 --- a/src/extract.c +++ b/src/extract.c @@ -739,37 +739,33 @@ extract_file (char *file_name, int typeflag) } } + 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) @@ -783,9 +779,8 @@ extract_file (char *file_name, int typeflag) 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. */ diff --git a/src/incremen.c b/src/incremen.c index 48de668..cc5856a 100644 --- a/src/incremen.c +++ b/src/incremen.c @@ -648,15 +648,11 @@ get_gnu_dumpdir () 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"))); @@ -668,8 +664,8 @@ get_gnu_dumpdir () 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 */ diff --git a/src/list.c b/src/list.c index 5bbd3cb..0c3e223 100644 --- a/src/list.c +++ b/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 (¤t_stat_info); skip_member (); - if (multi_volume_option) - assign_string (&save_name, 0); + mv_end (); } /* Check header checksum */ @@ -400,6 +398,7 @@ read_header (bool raw_extended_headers) { xheader_read (header, OFF_FROM_HEADER (header->header.size)); xheader_decode_global (); + xheader_destroy (&extended_header); } /* Loop! */ @@ -1269,25 +1268,19 @@ skip_file (off_t size) { 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 (); @@ -1296,8 +1289,7 @@ skip_file (off_t size) set_next_block_after (x); 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; 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 (); }