diff options
author | Timo Teräs <timo.teras@iki.fi> | 2021-07-17 17:57:07 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-07-22 15:30:08 +0300 |
commit | 796d29831360c55d8b8b7d9aa5f33c817094c1bf (patch) | |
tree | ddb51a2c60ece9f79b48b05c1d2845ef1ba4509e /src/app_fetch.c | |
parent | b559a81694d8a95ac786104516aebf98d04b84bc (diff) | |
download | apk-tools-796d29831360c55d8b8b7d9aa5f33c817094c1bf.tar.gz apk-tools-796d29831360c55d8b8b7d9aa5f33c817094c1bf.tar.bz2 apk-tools-796d29831360c55d8b8b7d9aa5f33c817094c1bf.tar.xz apk-tools-796d29831360c55d8b8b7d9aa5f33c817094c1bf.zip |
rework apk_istream_splice and apk_istream_tee
- apk_istream_splice usage is converted to apk_stream_copy which
is the newer variant. With caching enabled by default, this
makes more sense mmapping or using separate buffers.
- apk_istream_tee is reworked to write to apk_ostream, which simplifies
quite a bit of various things
Diffstat (limited to 'src/app_fetch.c')
-rw-r--r-- | src/app_fetch.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/app_fetch.c b/src/app_fetch.c index 870dda2..c54a8e0 100644 --- a/src/app_fetch.c +++ b/src/app_fetch.c @@ -120,10 +120,11 @@ static int fetch_package(apk_hash_item item, void *pctx) struct apk_out *out = &db->ctx->out; struct apk_package *pkg = (struct apk_package *) item; struct apk_istream *is; + struct apk_ostream *os; struct apk_repository *repo; struct apk_file_info fi; char url[PATH_MAX], filename[256]; - int r, fd, urlfd; + int r, urlfd; if (!pkg->marked) return 0; @@ -154,7 +155,7 @@ static int fetch_package(apk_hash_item item, void *pctx) goto err; if (ctx->flags & FETCH_STDOUT) { - fd = STDOUT_FILENO; + os = apk_ostream_to_fd(STDOUT_FILENO); } else { if ((ctx->flags & FETCH_LINK) && urlfd >= 0) { if (linkat(urlfd, url, @@ -162,10 +163,9 @@ static int fetch_package(apk_hash_item item, void *pctx) AT_SYMLINK_FOLLOW) == 0) return 0; } - fd = openat(ctx->outdir_fd, filename, - O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC, 0644); - if (fd < 0) { - r = -errno; + os = apk_ostream_to_file(ctx->outdir_fd, filename, 0644); + if (IS_ERR(os)) { + r = PTR_ERR(os); goto err; } } @@ -176,20 +176,11 @@ static int fetch_package(apk_hash_item item, void *pctx) goto err; } - r = apk_istream_splice(is, fd, pkg->size, progress_cb, ctx, 0); - if (fd != STDOUT_FILENO) { - struct apk_file_meta meta; - apk_istream_get_meta(is, &meta); - apk_file_meta_to_fd(fd, &meta); - close(fd); - } + apk_stream_copy(is, os, pkg->size, progress_cb, ctx, 0); + apk_ostream_copy_meta(os, is); apk_istream_close(is); - - if (r != pkg->size) { - unlinkat(ctx->outdir_fd, filename, 0); - if (r >= 0) r = -EIO; - goto err; - } + r = apk_ostream_close(os); + if (r) goto err; ctx->done += pkg->size; return 0; |