aboutsummaryrefslogtreecommitdiffstats
path: root/tools/gpgtar-extract.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2019-03-06 16:46:40 +0000
committerWerner Koch <[email protected]>2019-03-07 09:55:21 +0000
commit2e4151a3412c3fc553fbb7ad070dfffc68a04b35 (patch)
treec560fc28b0bd37ab821d91f41fb9f69300cbed67 /tools/gpgtar-extract.c
parentgpg: Make invalid primary key algos obvious in key listings. (diff)
downloadgnupg-2e4151a3412c3fc553fbb7ad070dfffc68a04b35.tar.gz
gnupg-2e4151a3412c3fc553fbb7ad070dfffc68a04b35.zip
gpgtar: Improve error messages.
* tools/gpgtar.h (struct tarinfo_s): New. * tools/gpgtar.c (cmd, skip_crypto, files_from, null_names): Move global vars more to the top. (set_cmd): Rename 'cmd' to 'c'. * tools/gpgtar-list.c (parse_header): Add arg 'info' and improve error messages. (read_header): Add arg 'info' and update counter. (skip_data): Ditto. (gpgtar_list): Pass info object to read functions. (gpgtar_read_header): Add arg 'info'. * tools/gpgtar-extract.c (gpgtar_extract): add arg 'info' and pass on. (extract_regular): Add arg 'info' and update counter. -- This now prints the block number of a header with error. Signed-off-by: Werner Koch <[email protected]> (cherry picked from commit 72feb8fa8280aba674573a1afc955a92e8065242)
Diffstat (limited to 'tools/gpgtar-extract.c')
-rw-r--r--tools/gpgtar-extract.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/tools/gpgtar-extract.c b/tools/gpgtar-extract.c
index 8613d193f..3da100c07 100644
--- a/tools/gpgtar-extract.c
+++ b/tools/gpgtar-extract.c
@@ -36,7 +36,7 @@
static gpg_error_t
extract_regular (estream_t stream, const char *dirname,
- tar_header_t hdr)
+ tarinfo_t info, tar_header_t hdr)
{
gpg_error_t err;
char record[RECORDSIZE];
@@ -70,6 +70,7 @@ extract_regular (estream_t stream, const char *dirname,
err = read_record (stream, record);
if (err)
goto leave;
+ info->nblocks++;
n++;
if (n < hdr->nrecords || (hdr->size && !(hdr->size % RECORDSIZE)))
nbytes = RECORDSIZE;
@@ -163,7 +164,8 @@ extract_directory (const char *dirname, tar_header_t hdr)
static gpg_error_t
-extract (estream_t stream, const char *dirname, tar_header_t hdr)
+extract (estream_t stream, const char *dirname, tarinfo_t info,
+ tar_header_t hdr)
{
gpg_error_t err;
size_t n;
@@ -190,7 +192,7 @@ extract (estream_t stream, const char *dirname, tar_header_t hdr)
}
if (hdr->typeflag == TF_REGULAR || hdr->typeflag == TF_UNKNOWN)
- err = extract_regular (stream, dirname, hdr);
+ err = extract_regular (stream, dirname, info, hdr);
else if (hdr->typeflag == TF_DIRECTORY)
err = extract_directory (dirname, hdr);
else
@@ -200,7 +202,11 @@ extract (estream_t stream, const char *dirname, tar_header_t hdr)
log_info ("unsupported file type %d for '%s' - skipped\n",
(int)hdr->typeflag, hdr->name);
for (err = 0, n=0; !err && n < hdr->nrecords; n++)
- err = read_record (stream, record);
+ {
+ err = read_record (stream, record);
+ if (!err)
+ info->nblocks++;
+ }
}
return err;
}
@@ -282,6 +288,10 @@ gpgtar_extract (const char *filename, int decrypt)
tar_header_t header = NULL;
const char *dirprefix = NULL;
char *dirname = NULL;
+ struct tarinfo_s tarinfo_buffer;
+ tarinfo_t tarinfo = &tarinfo_buffer;
+
+ memset (&tarinfo_buffer, 0, sizeof tarinfo_buffer);
if (filename)
{
@@ -378,11 +388,11 @@ gpgtar_extract (const char *filename, int decrypt)
for (;;)
{
- err = gpgtar_read_header (stream, &header);
+ err = gpgtar_read_header (stream, tarinfo, &header);
if (err || header == NULL)
goto leave;
- err = extract (stream, dirname, header);
+ err = extract (stream, dirname, tarinfo, header);
if (err)
goto leave;
xfree (header);