X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fbuffer.c;h=ab067520f54f9ef5cc05c876e3df3d0b22e14a4d;hb=7645d20465e8c37f8f246b7490cbffbb0107045d;hp=8874fe15848ccb5ede0b5d634b870b7fd0293f5f;hpb=664f2dbdd950ddd32587e3b325dd0a0cd48a50a7;p=chaz%2Ftar diff --git a/src/buffer.c b/src/buffer.c index 8874fe1..ab06752 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -669,8 +669,7 @@ open_archive (enum access_mode wanted_access) if (archive_names == 0) FATAL_ERROR ((0, 0, _("No archive name given"))); - current_file_name = 0; - current_link_name = 0; + destroy_stat (¤t_stat_info); save_name = 0; real_s_name = 0; @@ -845,8 +844,8 @@ open_archive (enum access_mode wanted_access) else strcpy (record_start->header.name, volume_label_option); - assign_string (¤t_file_name, record_start->header.name); - current_trailing_slash = strip_trailing_slashes (current_file_name); + assign_string (¤t_stat_info.file_name, record_start->header.name); + current_stat_info.had_trailing_slash = strip_trailing_slashes (current_stat_info.file_name); record_start->header.typeflag = GNUTYPE_VOLHDR; TIME_TO_CHARS (start_time, record_start->header.mtime); @@ -1036,13 +1035,52 @@ archive_read_error (void) return; } +static void +short_read (ssize_t status) +{ + size_t left; /* bytes left */ + char *more; /* pointer to next byte to read */ + + more = record_start->buffer + status; + left = record_size - status; + + while (left % BLOCKSIZE != 0 + || (left && status && read_full_records_option)) + { + if (status) + while ((status = rmtread (archive, more, left)) < 0) + archive_read_error (); + + if (status == 0) + break; + + if (! read_full_records_option) + FATAL_ERROR ((0, 0, _("Unaligned block (%lu bytes) in archive"), + (unsigned long) (record_size - left))); + + /* User warned us about this. Fix up. */ + + left -= status; + more += status; + } + + /* FIXME: for size=0, multi-volume support. On the first record, warn + about the problem. */ + + if (!read_full_records_option && verbose_option + && record_start_block == 0 && status > 0) + WARN ((0, 0, _("Record size = %lu blocks"), + (unsigned long) ((record_size - left) / BLOCKSIZE))); + + record_end = record_start + (record_size - left) / BLOCKSIZE; + records_read++; +} + /* Perform a read to flush the buffer. */ void flush_read (void) { ssize_t status; /* result from system call */ - size_t left; /* bytes left */ - char *more; /* pointer to next byte to read */ if (checkpoint_option && !(++checkpoint % 10)) WARN ((0, 0, _("Read checkpoint %d"), checkpoint)); @@ -1115,7 +1153,7 @@ flush_read (void) goto vol_error; } if (status != record_size) - goto short_read; + short_read (status); cursor = record_start; @@ -1189,40 +1227,7 @@ flush_read (void) goto error_loop; /* try again */ } - short_read: - more = record_start->buffer + status; - left = record_size - status; - - while (left % BLOCKSIZE != 0 - || (left && status && read_full_records_option)) - { - if (status) - while ((status = rmtread (archive, more, left)) < 0) - archive_read_error (); - - if (status == 0) - break; - - if (! read_full_records_option) - FATAL_ERROR ((0, 0, _("Unaligned block (%lu bytes) in archive"), - (unsigned long) (record_size - left))); - - /* User warned us about this. Fix up. */ - - left -= status; - more += status; - } - - /* FIXME: for size=0, multi-volume support. On the first record, warn - about the problem. */ - - if (!read_full_records_option && verbose_option - && record_start_block == 0 && status > 0) - WARN ((0, 0, _("Record size = %lu blocks"), - (unsigned long) ((record_size - left) / BLOCKSIZE))); - - record_end = record_start + (record_size - left) / BLOCKSIZE; - records_read++; + short_read (status); } /* Flush the current buffer to/from the archive. */ @@ -1356,10 +1361,7 @@ close_archive (void) } #endif /* !MSDOS */ - if (current_file_name) - free (current_file_name); - if (current_link_name) - free (current_link_name); + destroy_stat (¤t_stat_info); if (save_name) free (save_name); if (real_s_name) @@ -1551,7 +1553,12 @@ new_volume (enum access_mode access) } } - if (verify_option) + if (strcmp (archive_name_cursor[0], "-") == 0) + { + read_full_records_option = true; + archive = STDIN_FILENO; + } + else if (verify_option) archive = rmtopen (*archive_name_cursor, O_RDWR | O_CREAT, MODE_RW, rsh_command_option); else @@ -1589,3 +1596,4 @@ new_volume (enum access_mode access) return 1; } +