summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-11-05 13:20:19 +0200
committerTimo Teräs <timo.teras@iki.fi>2021-11-09 21:50:11 +0200
commita6736532001fd625f1ab3dd82abc2a4c5366c79c (patch)
tree47ead4bc00519f0b1e3ea52bf576da5bb8b66530 /src/io.c
parentd441cf523cea6ab2d2ee1c0f50fab0bb620f2ea1 (diff)
downloadapk-tools-a6736532001fd625f1ab3dd82abc2a4c5366c79c.tar.gz
apk-tools-a6736532001fd625f1ab3dd82abc2a4c5366c79c.tar.bz2
apk-tools-a6736532001fd625f1ab3dd82abc2a4c5366c79c.tar.xz
apk-tools-a6736532001fd625f1ab3dd82abc2a4c5366c79c.zip
database: implement uvol support
by adding an abstraction layer to the file system
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/io.c b/src/io.c
index a8821e4..cf30bb6 100644
--- a/src/io.c
+++ b/src/io.c
@@ -314,7 +314,10 @@ static ssize_t digest_read(struct apk_istream *is, void *ptr, size_t size)
ssize_t r;
r = dis->pis->ops->read(dis->pis, ptr, size);
- if (r > 0) apk_digest_ctx_update(&dis->dctx, ptr, r);
+ if (r > 0) {
+ apk_digest_ctx_update(&dis->dctx, ptr, r);
+ dis->size_left -= r;
+ }
return r;
}
@@ -322,7 +325,7 @@ static int digest_close(struct apk_istream *is)
{
struct apk_digest_istream *dis = container_of(is, struct apk_digest_istream, is);
- if (dis->digest) {
+ if (dis->digest && dis->size_left == 0) {
struct apk_digest res;
apk_digest_ctx_final(&dis->dctx, &res);
if (apk_digest_cmp(&res, dis->digest) != 0)
@@ -340,7 +343,7 @@ static const struct apk_istream_ops digest_istream_ops = {
.close = digest_close,
};
-struct apk_istream *apk_istream_verify(struct apk_digest_istream *dis, struct apk_istream *is, struct apk_digest *d)
+struct apk_istream *apk_istream_verify(struct apk_digest_istream *dis, struct apk_istream *is, off_t size, struct apk_digest *d)
{
*dis = (struct apk_digest_istream) {
.is.ops = &digest_istream_ops,
@@ -350,10 +353,13 @@ struct apk_istream *apk_istream_verify(struct apk_digest_istream *dis, struct ap
.is.end = is->end,
.pis = is,
.digest = d,
+ .size_left = size,
};
apk_digest_ctx_init(&dis->dctx, d->alg);
- if (dis->is.ptr != dis->is.end)
+ if (dis->is.ptr != dis->is.end) {
apk_digest_ctx_update(&dis->dctx, dis->is.ptr, dis->is.end - dis->is.ptr);
+ dis->size_left -= dis->is.end - dis->is.ptr;
+ }
return &dis->is;
}