1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
From 445ea072205cfb2d9ecd9ffb28d88023d5d24ea5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Tue, 16 Feb 2016 15:19:15 +0200
Subject: [PATCH] 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
---
src/fetch.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
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;
}
--
2.7.1
|