From a6736532001fd625f1ab3dd82abc2a4c5366c79c Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Fri, 5 Nov 2021 13:20:19 +0200 Subject: database: implement uvol support by adding an abstraction layer to the file system --- src/io.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/io.c') 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; } -- cgit v1.2.3-70-g09d2