diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/apk_defines.h | 3 | ||||
-rw-r--r-- | src/archive.c | 3 | ||||
-rw-r--r-- | src/commit.c | 8 | ||||
-rw-r--r-- | src/database.c | 23 | ||||
-rw-r--r-- | src/io.c | 4 |
5 files changed, 11 insertions, 30 deletions
diff --git a/src/apk_defines.h b/src/apk_defines.h index 629ca7b..00a6f9e 100644 --- a/src/apk_defines.h +++ b/src/apk_defines.h @@ -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) \ diff --git a/src/archive.c b/src/archive.c index 1ab7961..8f22f42 100644 --- a/src/archive.c +++ b/src/archive.c @@ -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 { diff --git a/src/commit.c b/src/commit.c index 857c7bc..e55843e 100644 --- a/src/commit.c +++ b/src/commit.c @@ -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; diff --git a/src/database.c b/src/database.c index bdfb5fb..cff38c0 100644 --- a/src/database.c +++ b/src/database.c @@ -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) |