From: Tim Kientzle Date: Sun, 16 May 2010 20:33:30 +0000 (-0400) Subject: Properly support filter(-1) as a shorthand for "the last filter", X-Git-Tag: v3.0.0a~1001 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a154d88f95b647e64d3c197eb5d88b914d9bec0;p=thirdparty%2Flibarchive.git Properly support filter(-1) as a shorthand for "the last filter", which is always the client proxy. In particular, tar uses this for reporting position in the input stream. SVN-Revision: 2403 --- diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c index 59a4c490a..9cdc23f17 100644 --- a/libarchive/archive_read.c +++ b/libarchive/archive_read.c @@ -864,7 +864,16 @@ get_filter(struct archive *_a, int n) { struct archive_read *a = (struct archive_read *)_a; struct archive_read_filter *f = a->filter; - /* XXX handle n == -1 */ + /* We use n == -1 for 'the last filter', which is always the client proxy. */ + if (n == -1 && f != NULL) { + struct archive_read_filter *last = f; + f = f->upstream; + while (f != NULL) { + last = f; + f = f->upstream; + } + return (last); + } if (n < 0) return NULL; while (n > 0 && f != NULL) { @@ -1095,6 +1104,7 @@ __archive_read_filter_ahead(struct archive_read_filter *filter, bytes_read = (filter->read)(filter, &filter->client_buff); if (bytes_read < 0) { /* Read error. */ +fprintf(stderr, "Filter read ahead saw bytes_read=%d\n", bytes_read); filter->client_total = filter->client_avail = 0; filter->client_next = filter->client_buff = NULL; filter->fatal = 1; @@ -1272,6 +1282,7 @@ advance_file_pointer(struct archive_read_filter *filter, int64_t request) bytes_read = (filter->read)(filter, &filter->client_buff); if (bytes_read < 0) { + fprintf(stderr, "Filter skip saw bytes_read=%d\n", bytes_read); filter->client_buff = NULL; filter->fatal = 1; return (bytes_read);