- }
- if (save_typeflag == GNUTYPE_SPARSE)
- {
- if (finish_sparse_file (f, &sizeleft, current_stat.st_size, p))
- goto padit;
- }
- else
- while (sizeleft > 0)
- {
- if (multi_volume_option)
- {
- assign_string (&save_name, p);
- save_sizeleft = sizeleft;
- save_totsize = current_stat.st_size;
- }
- start = find_next_block ();
-
- bufsize = available_space_after (start);
-
- if (sizeleft < bufsize)
- {
- /* Last read -- zero out area beyond. */
-
- bufsize = sizeleft;
- count = bufsize % BLOCKSIZE;
- if (count)
- memset (start->buffer + sizeleft, 0,
- (size_t) (BLOCKSIZE - count));
- }
- if (f < 0)
- count = bufsize;
- else
- count = read (f, start->buffer, bufsize);
- if (count < 0)
- {
- char buf[UINTMAX_STRSIZE_BOUND];
- ERROR ((0, errno, _("\
-Read error at byte %s, reading %lu bytes, in file %s"),
- STRINGIFY_BIGINT (current_stat.st_size - sizeleft,
- buf),
- (unsigned long) bufsize, p));
- goto padit;
- }
- sizeleft -= count;
-
- /* This is nonportable (the type of set_next_block_after's arg). */
-
- set_next_block_after (start + (count - 1) / BLOCKSIZE);
-
- if (count == bufsize)
- continue;
- else
- {
- char buf[UINTMAX_STRSIZE_BOUND];
- ERROR ((0, 0,
- _("File %s shrunk by %s bytes, padding with zeros"),
- p, STRINGIFY_BIGINT (sizeleft, buf)));
- goto padit; /* short read */
- }
- }
-
- if (multi_volume_option)
- assign_string (&save_name, NULL);
-
- if (f >= 0)
- {
- struct stat final_stat;
- if (fstat (f, &final_stat) != 0)
- ERROR ((0, errno, "%s: fstat", p));
- else if (final_stat.st_mtime != restore_times.modtime
- || final_stat.st_size != restore_size)
- ERROR ((0, errno, _("%s: file changed as we read it"), p));
- if (close (f) != 0)
- ERROR ((0, errno, _("%s: close"), p));
- if (atime_preserve_option)
- utime (p, &restore_times);
- }
- if (remove_files_option)
- {
- if (unlink (p) == -1)
- ERROR ((0, errno, _("Cannot remove %s"), p));
- }
- return;
-
- /* File shrunk or gave error, pad out tape to match the size we
- specified in the header. */
-
- padit:
- while (sizeleft > 0)
- {
- save_sizeleft = sizeleft;
- start = find_next_block ();
- memset (start->buffer, 0, BLOCKSIZE);
- set_next_block_after (start);
- sizeleft -= BLOCKSIZE;
- }
- if (multi_volume_option)
- assign_string (&save_name, NULL);
- if (f >= 0)
- {
- close (f);