Commit 656190b0 authored by Timo Teräs's avatar Timo Teräs

io: get rid of APK_PROGRESS_SCALE

no need to muldiv all the time, just pass the current amount of bytes
done, and let callbacks use that directly.
parent ade8d0b4
......@@ -16,6 +16,7 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define BIT(x) (1 << (x))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#ifndef TRUE
......@@ -102,8 +103,6 @@ static inline size_t muldiv(size_t a, size_t b, size_t c)
typedef void (*apk_progress_cb)(void *cb_ctx, size_t);
#define APK_PROGRESS_SCALE 0x100
void *apk_array_resize(void *array, size_t new_size, size_t elem_size);
#define APK_ARRAY(array_type_name, elem_type_name) \
......
......@@ -363,8 +363,7 @@ int apk_archive_entry_extract(int atfd, const struct apk_file_info *ae,
r = -1;
break;
}
if (apk_istream_splice(is, fd, ae->size, cb, cb_ctx)
== ae->size)
if (apk_istream_splice(is, fd, ae->size, cb, cb_ctx) == ae->size)
r = 0;
close(fd);
} else {
......
......@@ -125,16 +125,14 @@ struct progress {
int flags;
};
static void progress_cb(void *ctx, size_t pkg_percent)
static void progress_cb(void *ctx, size_t installed_bytes)
{
struct progress *prog = (struct progress *) ctx;
size_t partial = 0, percent, total;
size_t percent, total;
if (prog->pkg != NULL)
partial = muldiv(pkg_percent, prog->pkg->installed_size, APK_PROGRESS_SCALE);
total = prog->total.bytes + prog->total.packages;
if (total > 0)
percent = muldiv(100, prog->done.bytes + prog->done.packages + partial,
percent = muldiv(100, prog->done.bytes + prog->done.packages + installed_bytes,
prog->total.bytes + prog->total.packages);
else
percent = 0;
......
......@@ -2133,19 +2133,12 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t _repository)
return 0;
}
static void extract_cb(void *_ctx, size_t progress)
static void extract_cb(void *_ctx, size_t bytes_done)
{
struct install_ctx *ctx = (struct install_ctx *) _ctx;
if (ctx->cb) {
size_t size = ctx->installed_size;
size += muldiv(progress, ctx->current_file_size, APK_PROGRESS_SCALE);
if (size > ctx->pkg->installed_size)
size = ctx->pkg->installed_size;
ctx->cb(ctx->cb_ctx, muldiv(APK_PROGRESS_SCALE, size, ctx->pkg->installed_size));
}
if (!ctx->cb)
return;
ctx->cb(ctx->cb_ctx, min(ctx->installed_size + bytes_done, ctx->pkg->installed_size));
}
static int apk_db_run_pending_script(struct install_ctx *ctx)
......@@ -2256,14 +2249,6 @@ static int apk_db_install_archive_entry(void *_ctx,
if (r != 0)
return r;
/* Show progress */
if (ctx->cb) {
size_t size = ctx->installed_size;
if (size > pkg->installed_size)
size = pkg->installed_size;
ctx->cb(ctx->cb_ctx, muldiv(APK_PROGRESS_SCALE, size, pkg->installed_size));
}
/* Installable entry */
ctx->current_file_size = apk_calc_installed_size(ae->size);
if (!S_ISDIR(ae->mode)) {
......
......@@ -156,8 +156,8 @@ size_t apk_istream_splice(void *stream, int fd, size_t size,
}
while (done < size) {
if (done != 0 && cb != NULL)
cb(cb_ctx, muldiv(APK_PROGRESS_SCALE, done, size));
if (cb != NULL)
cb(cb_ctx, done);
togo = size - done;
if (togo > bufsz)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment