]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Properly support filter(-1) as a shorthand for "the last filter",
authorTim Kientzle <kientzle@gmail.com>
Sun, 16 May 2010 20:33:30 +0000 (16:33 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sun, 16 May 2010 20:33:30 +0000 (16:33 -0400)
which is always the client proxy.  In particular, tar uses this for
reporting position in the input stream.

SVN-Revision: 2403

libarchive/archive_read.c

index 59a4c490ab8b7c1b835e365b11ffbc87a4185b38..9cdc23f174bf92d80bb0b4297542f2b7f56efe7f 100644 (file)
@@ -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);