summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apk.c37
-rw-r--r--src/apk_applet.h2
-rw-r--r--src/apk_database.h1
-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.c4
9 files changed, 47 insertions, 7 deletions
diff --git a/src/apk.c b/src/apk.c
index 0c8286c..a101cf6 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -284,6 +284,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_db_options *dbopts, 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;
+
+ dbopts->open_flags &= ~all_flags;
+ dbopts->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_applet *applet)
{
version();
diff --git a/src/apk_applet.h b/src/apk_applet.h
index 0ae33b4..1e5b74f 100644
--- a/src/apk_applet.h
+++ b/src/apk_applet.h
@@ -61,7 +61,7 @@ struct apk_applet {
int (*main)(void *ctx, struct apk_database *db, struct apk_string_array *args);
};
-extern const struct apk_option_group optgroup_global, optgroup_commit;
+extern const struct apk_option_group optgroup_global, optgroup_commit, optgroup_source;
void apk_applet_register(struct apk_applet *);
struct apk_applet *apk_applet_find(const char *name);
diff --git a/src/apk_database.h b/src/apk_database.h
index 5818eb4..f70ae1c 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -229,6 +229,7 @@ struct apk_db_file *apk_db_file_query(struct apk_database *db,
#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_INSTALLED_REPO)
diff --git a/src/app_dot.c b/src/app_dot.c
index 64c3f87..6f63bd9 100644
--- a/src/app_dot.c
+++ b/src/app_dot.c
@@ -162,7 +162,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 6b40786..11602c1 100644
--- a/src/app_fetch.c
+++ b/src/app_fetch.c
@@ -392,7 +392,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 cf7f58f..8ba0c10 100644
--- a/src/app_info.c
+++ b/src/app_info.c
@@ -473,7 +473,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 fed9aa9..d3848ec 100644
--- a/src/app_list.c
+++ b/src/app_list.c
@@ -248,7 +248,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 db4c398..a3f38e3 100644
--- a/src/app_search.c
+++ b/src/app_search.c
@@ -195,7 +195,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 58c00d4..3b5bc38 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1726,10 +1726,12 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
}
}
- if (!(dbopts->open_flags & APK_OPENF_NO_SYS_REPOS)) {
+ if (!(dbopts->open_flags & APK_OPENF_NO_CMDLINE_REPOS)) {
list_for_each_entry(repo, &dbopts->repository_list, list)
apk_db_add_repository(db, APK_BLOB_STR(repo->url));
+ }
+ if (!(dbopts->open_flags & APK_OPENF_NO_SYS_REPOS)) {
if (dbopts->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),