summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2013-06-17 17:13:14 +0300
committerTimo Teräs <timo.teras@iki.fi>2013-06-17 17:13:14 +0300
commitade8d0b4e9c206ab67dc8ef2006e8070011aae83 (patch)
tree6e9df56d13cfd344d0b1ab0e26012a20257c52ab /src/io.c
parent0a131418899436b58a163978176d99c08cbddb0c (diff)
downloadapk-tools-ade8d0b4e9c206ab67dc8ef2006e8070011aae83.tar.gz
apk-tools-ade8d0b4e9c206ab67dc8ef2006e8070011aae83.tar.bz2
apk-tools-ade8d0b4e9c206ab67dc8ef2006e8070011aae83.tar.xz
apk-tools-ade8d0b4e9c206ab67dc8ef2006e8070011aae83.zip
cache: implement progress bar (ref #1170)
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/io.c b/src/io.c
index 667d9aa..20ea28a 100644
--- a/src/io.c
+++ b/src/io.c
@@ -385,6 +385,8 @@ struct apk_tee_bstream {
struct apk_bstream *inner_bs;
int fd;
size_t size;
+ apk_progress_cb cb;
+ void *cb_ctx;
};
static apk_blob_t tee_read(void *stream, apk_blob_t token)
@@ -394,8 +396,11 @@ static apk_blob_t tee_read(void *stream, apk_blob_t token)
apk_blob_t blob;
blob = tbs->inner_bs->read(tbs->inner_bs, token);
- if (!APK_BLOB_IS_NULL(blob))
+ if (!APK_BLOB_IS_NULL(blob)) {
tbs->size += write(tbs->fd, blob.ptr, blob.len);
+ if (tbs->cb)
+ tbs->cb(tbs->cb_ctx, tbs->size);
+ }
return blob;
}
@@ -412,7 +417,7 @@ static void tee_close(void *stream, size_t *size)
free(tbs);
}
-struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const char *to)
+struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const char *to, apk_progress_cb cb, void *cb_ctx)
{
struct apk_tee_bstream *tbs;
int fd;
@@ -435,6 +440,8 @@ struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const ch
tbs->inner_bs = from;
tbs->fd = fd;
tbs->size = 0;
+ tbs->cb = cb;
+ tbs->cb_ctx = cb_ctx;
return &tbs->bs;
}