summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2013-06-17 17:28:03 +0300
committerTimo Teräs <timo.teras@iki.fi>2013-06-17 17:28:03 +0300
commit656190b0a063686b9bd675bbffe43fbebf4aacab (patch)
tree3f0336fb2080b938fc447ed4c155769be0211fb2
parentade8d0b4e9c206ab67dc8ef2006e8070011aae83 (diff)
downloadapk-tools-656190b0a063686b9bd675bbffe43fbebf4aacab.tar.gz
apk-tools-656190b0a063686b9bd675bbffe43fbebf4aacab.tar.bz2
apk-tools-656190b0a063686b9bd675bbffe43fbebf4aacab.tar.xz
apk-tools-656190b0a063686b9bd675bbffe43fbebf4aacab.zip
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.
-rw-r--r--src/apk_defines.h3
-rw-r--r--src/archive.c3
-rw-r--r--src/commit.c8
-rw-r--r--src/database.c23
-rw-r--r--src/io.c4
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)) {
diff --git a/src/io.c b/src/io.c
index 20ea28a..3b19c63 100644
--- a/src/io.c
+++ b/src/io.c
@@ -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)