summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2016-02-16 15:19:15 +0200
committerTimo Teräs <timo.teras@iki.fi>2016-02-16 15:19:52 +0200
commit445ea072205cfb2d9ecd9ffb28d88023d5d24ea5 (patch)
tree7285a08987facb67d8513a3b22f8aa22650b7ad5
parent22d56cfe28ed53f3bf3d53dc606ae45748c5bb7d (diff)
downloadapk-tools-445ea072205cfb2d9ecd9ffb28d88023d5d24ea5.tar.gz
apk-tools-445ea072205cfb2d9ecd9ffb28d88023d5d24ea5.tar.bz2
apk-tools-445ea072205cfb2d9ecd9ffb28d88023d5d24ea5.tar.xz
apk-tools-445ea072205cfb2d9ecd9ffb28d88023d5d24ea5.zip
implement fetch --purge
which will delete any .apk package on output directory that were not downloaded by fetch this allows apk fetch to incrementally build repositories for binary images
-rw-r--r--src/fetch.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/fetch.c b/src/fetch.c
index 3bb7934..14e0790 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -264,6 +264,37 @@ err:
mark_error(ctx, match, name);
}
+static int purge_package(void *pctx, int dirfd, const char *filename)
+{
+ char tmp[PATH_MAX];
+ struct fetch_ctx *ctx = (struct fetch_ctx *) pctx;
+ struct apk_database *db = ctx->db;
+ struct apk_provider *p0;
+ struct apk_name *name;
+ apk_blob_t b = APK_BLOB_STR(filename), bname, bver;
+ size_t l;
+
+ if (apk_pkg_parse_name(b, &bname, &bver)) return 0;
+ name = apk_db_get_name(db, bname);
+ if (!name) return 0;
+
+ foreach_array_item(p0, name->providers) {
+ if (p0->pkg->name != name) continue;
+ l = snprintf(tmp, sizeof tmp, PKG_FILE_FMT, PKG_FILE_PRINTF(p0->pkg));
+ if (l > sizeof tmp) continue;
+ if (apk_blob_compare(b, APK_BLOB_PTR_LEN(tmp, l)) != 0) continue;
+ if (p0->pkg->marked) return 0;
+ break;
+ }
+
+ apk_message("Purging %s", filename);
+ if (apk_flags & APK_SIMULATE)
+ return 0;
+
+ unlinkat(dirfd, filename, 0);
+ return 0;
+}
+
static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
{
struct fetch_ctx *ctx = (struct fetch_ctx *) pctx;
@@ -290,6 +321,11 @@ static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_arr
if (!ctx->errors)
apk_hash_foreach(&db->available.packages, fetch_package, ctx);
+ /* Remove packages not matching download spec from the output directory */
+ if (!ctx->errors && (apk_flags & APK_PURGE) &&
+ !(ctx->flags & FETCH_STDOUT) && ctx->outdir_fd > 0)
+ apk_dir_foreach_file(ctx->outdir_fd, purge_package, ctx);
+
return ctx->errors;
}