summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2023-03-23 13:12:34 +0200
committerTimo Teräs <timo.teras@iki.fi>2023-03-23 13:13:49 +0200
commitd5ff6c96e41210f5a88ba48d85513751e36868f4 (patch)
treeb1dfb01114e4767b8866a69daeb0c2e20cc6e1ea /src
parent27291bd5fcd6e069551f82865ec3fc3de69a4239 (diff)
downloadapk-tools-d5ff6c96e41210f5a88ba48d85513751e36868f4.tar.gz
apk-tools-d5ff6c96e41210f5a88ba48d85513751e36868f4.tar.bz2
apk-tools-d5ff6c96e41210f5a88ba48d85513751e36868f4.tar.xz
apk-tools-d5ff6c96e41210f5a88ba48d85513751e36868f4.zip
db, dot, fetch, info, list, search: support --from=FROMSPEC
Allow omitting loading of system installed database and system repositories for the commands that operate on package indexes only.
Diffstat (limited to 'src')
-rw-r--r--src/apk.c37
-rw-r--r--src/apk_applet.h2
-rw-r--r--src/apk_context.h2
-rw-r--r--src/app_dot.c2
-rw-r--r--src/app_fetch.c2
-rw-r--r--src/app_info.c2
-rw-r--r--src/app_list.c2
-rw-r--r--src/app_search.c2
-rw-r--r--src/database.c5
9 files changed, 48 insertions, 8 deletions
diff --git a/src/apk.c b/src/apk.c
index 045a094..a937be8 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -278,6 +278,43 @@ const struct apk_option_group optgroup_commit = {
.parse = option_parse_commit,
};
+#define SOURCE_OPTIONS(OPT) \
+ OPT(OPT_SOURCE_from, APK_OPT_ARG "from")
+
+APK_OPT_GROUP(optiondesc_source, "Source", SOURCE_OPTIONS);
+
+static int option_parse_source(void *ctx, struct apk_ctx *ac, int opt, const char *optarg)
+{
+ const unsigned long all_flags = APK_OPENF_NO_SYS_REPOS | APK_OPENF_NO_INSTALLED_REPO | APK_OPENF_NO_INSTALLED;
+ unsigned long flags;
+
+ switch (opt) {
+ case OPT_SOURCE_from:
+ if (strcmp(optarg, "none") == 0) {
+ flags = APK_OPENF_NO_SYS_REPOS | APK_OPENF_NO_INSTALLED_REPO | APK_OPENF_NO_INSTALLED;
+ } else if (strcmp(optarg, "repositories") == 0) {
+ flags = APK_OPENF_NO_INSTALLED_REPO | APK_OPENF_NO_INSTALLED;
+ } else if (strcmp(optarg, "installed") == 0) {
+ flags = APK_OPENF_NO_SYS_REPOS;
+ } else if (strcmp(optarg, "system") == 0) {
+ flags = 0;
+ } else
+ return -ENOTSUP;
+
+ ac->open_flags &= ~all_flags;
+ ac->open_flags |= flags;
+ break;
+ default:
+ return -ENOTSUP;
+ }
+ return 0;
+}
+
+const struct apk_option_group optgroup_source = {
+ .desc = optiondesc_source,
+ .parse = option_parse_source,
+};
+
static int usage(struct apk_out *out, struct apk_applet *applet)
{
version(out, NULL);
diff --git a/src/apk_applet.h b/src/apk_applet.h
index 0d63712..0715481 100644
--- a/src/apk_applet.h
+++ b/src/apk_applet.h
@@ -53,7 +53,7 @@ struct apk_applet {
int (*main)(void *ctx, struct apk_ctx *ac, struct apk_string_array *args);
};
-extern const struct apk_option_group optgroup_global, optgroup_commit, optgroup_signing;
+extern const struct apk_option_group optgroup_global, optgroup_commit, optgroup_signing, optgroup_source;
void apk_applet_register(struct apk_applet *);
struct apk_applet *apk_applet_find(const char *name);
diff --git a/src/apk_context.h b/src/apk_context.h
index ac0d3d3..6a0a758 100644
--- a/src/apk_context.h
+++ b/src/apk_context.h
@@ -48,8 +48,10 @@
#define APK_OPENF_NO_INSTALLED_REPO 0x0200
#define APK_OPENF_CACHE_WRITE 0x0400
#define APK_OPENF_NO_AUTOUPDATE 0x0800
+#define APK_OPENF_NO_CMDLINE_REPOS 0x1000
#define APK_OPENF_NO_REPOS (APK_OPENF_NO_SYS_REPOS | \
+ APK_OPENF_NO_CMDLINE_REPOS | \
APK_OPENF_NO_INSTALLED_REPO)
#define APK_OPENF_NO_STATE (APK_OPENF_NO_INSTALLED | \
APK_OPENF_NO_SCRIPTS | \
diff --git a/src/app_dot.c b/src/app_dot.c
index da12919..a82d02f 100644
--- a/src/app_dot.c
+++ b/src/app_dot.c
@@ -163,7 +163,7 @@ static struct apk_applet apk_dot = {
.name = "dot",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.context_size = sizeof(struct dot_ctx),
- .optgroups = { &optgroup_global, &optgroup_applet },
+ .optgroups = { &optgroup_global, &optgroup_source, &optgroup_applet },
.main = dot_main,
};
diff --git a/src/app_fetch.c b/src/app_fetch.c
index f9fdcf1..03c4b2a 100644
--- a/src/app_fetch.c
+++ b/src/app_fetch.c
@@ -390,7 +390,7 @@ static struct apk_applet apk_fetch = {
.name = "fetch",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.context_size = sizeof(struct fetch_ctx),
- .optgroups = { &optgroup_global, &optgroup_applet },
+ .optgroups = { &optgroup_global, &optgroup_source, &optgroup_applet },
.main = fetch_main,
};
diff --git a/src/app_info.c b/src/app_info.c
index b7174ac..92879f1 100644
--- a/src/app_info.c
+++ b/src/app_info.c
@@ -472,7 +472,7 @@ static struct apk_applet apk_info = {
.name = "info",
.open_flags = APK_OPENF_READ,
.context_size = sizeof(struct info_ctx),
- .optgroups = { &optgroup_global, &optgroup_applet },
+ .optgroups = { &optgroup_global, &optgroup_source, &optgroup_applet },
.main = info_main,
};
diff --git a/src/app_list.c b/src/app_list.c
index d15de94..846647b 100644
--- a/src/app_list.c
+++ b/src/app_list.c
@@ -263,7 +263,7 @@ static struct apk_applet apk_list = {
.name = "list",
.open_flags = APK_OPENF_READ,
.context_size = sizeof(struct list_ctx),
- .optgroups = { &optgroup_global, &optgroup_applet },
+ .optgroups = { &optgroup_global, &optgroup_source, &optgroup_applet },
.main = list_main,
};
diff --git a/src/app_search.c b/src/app_search.c
index ab51d6d..149d2a0 100644
--- a/src/app_search.c
+++ b/src/app_search.c
@@ -198,7 +198,7 @@ static struct apk_applet apk_search = {
.name = "search",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.context_size = sizeof(struct search_ctx),
- .optgroups = { &optgroup_global, &optgroup_applet },
+ .optgroups = { &optgroup_global, &optgroup_source, &optgroup_applet },
.main = search_main,
};
diff --git a/src/database.c b/src/database.c
index eedbbf0..86a396c 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1786,12 +1786,13 @@ int apk_db_open(struct apk_database *db, struct apk_ctx *ac)
}
}
- if (!(ac->open_flags & APK_OPENF_NO_SYS_REPOS)) {
+ if (!(ac->open_flags & APK_OPENF_NO_CMDLINE_REPOS)) {
char **repo;
-
foreach_array_item(repo, ac->repository_list)
apk_db_add_repository(db, APK_BLOB_STR(*repo));
+ }
+ if (!(ac->open_flags & APK_OPENF_NO_SYS_REPOS)) {
if (ac->repositories_file == NULL) {
add_repos_from_file(db, db->root_fd, "etc/apk/repositories");
apk_dir_foreach_file(openat(db->root_fd, "etc/apk/repositories.d", O_RDONLY | O_CLOEXEC),