summaryrefslogtreecommitdiff
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
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.
-rw-r--r--doc/apk.8.scd13
-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
10 files changed, 60 insertions, 9 deletions
diff --git a/doc/apk.8.scd b/doc/apk.8.scd
index edaa031..e8bb966 100644
--- a/doc/apk.8.scd
+++ b/doc/apk.8.scd
@@ -57,7 +57,7 @@ Each command is documented in detail on its manual page.
|[ *apk-index*(8)
:< Create repository index file from packages
| *apk-fetch*(8)
-: Download packages from global repositories to a local directory
+: Download packages from repositories to a local directory
| *apk-manifest*(8)
: Show checksums of package contents
| *apk-verify*(8)
@@ -215,6 +215,17 @@ The following options are available for all commands which commit the database.
force options to minimize failure, and disables commit hooks, among
other features.
+
+# SOURCE OPTIONS
+
+The following options are available for all commands which operate on the
+package indexes only.
+
+*--from* _FROMSPEC_
+ Search packages from: *system* (all system sources), *repositories*
+ (exclude installed database), *installed* (exclude normal repositories)
+ or *none* (commandline repositories only).
+
# NOTES
This apk has coffee making abilities.
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),