[pacman-dev] [PATCH 2/3] pacman: add front end support for repo usage level

Dave Reisner dreisner at archlinux.org
Sun Aug 4 13:25:12 EDT 2013


Add a "Usage" key to the repo section of the config which allows for the
tokens "Search", "Install", "Upgrade", "All", which correspond to values
in the alpm_db_usage_t enum. Users can specify "Usage" multiple times
for a given repo, or multiple flags per "Usage" line and they will be
OR'd together. If unspecified, the default is full usage of the repo.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
 doc/pacman.conf.5.txt | 18 +++++++++++++++++
 src/pacman/conf.c     | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/pacman/sync.c     | 11 +++++++++++
 3 files changed, 82 insertions(+)

diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt
index 049faee..ba471b4 100644
--- a/doc/pacman.conf.5.txt
+++ b/doc/pacman.conf.5.txt
@@ -243,6 +243,24 @@ even be used for different architectures.
 	Set the signature verification level for this repository. For more
 	information, see <<SC,Package and Database Signature Checking>> below.
 
+*Usage =* ...::
+	Set the usage level for this repository. This option takes a list of tokens
+	which must be at least one of the following:
+		*Sync*;;
+			Enables refreshes for this repository.
+		*Search*;;
+			Enables searching for this repository.
+		*Install*;;
+			Enables installation of packages from this repository during a '\--sync'
+			operation.
+		*Upgrade*;;
+			Allows this repository to be a valid source of packages when performing
+			a '\--sysupgrade'.
+		*All*;;
+			Enables all of the above features for the repository. This is the default
+			if not specified.
+
+
 Package and Database Signature Checking[[SC]]
 ---------------------------------------------
 The 'SigLevel' directive is valid in both the `[options]` and repository
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index ab6dae0..e6f8cf3 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -749,6 +749,7 @@ struct section_t {
 	/* db section option gathering */
 	alpm_siglevel_t siglevel;
 	alpm_list_t *servers;
+	alpm_db_usage_t usage;
 };
 
 /**
@@ -782,6 +783,12 @@ static int finish_section(struct section_t *section, int parse_options)
 		goto cleanup;
 	}
 
+	pm_printf(ALPM_LOG_DEBUG,
+			"setting usage of %d for %s repoistory\n",
+			section->usage == 0 ? ALPM_DB_USAGE_ALL : section->usage,
+			section->name);
+	alpm_db_set_usage(db, section->usage == 0 ? ALPM_DB_USAGE_ALL : section->usage);
+
 	for(i = section->servers; i; i = alpm_list_next(i)) {
 		char *value = i->data;
 		if(_add_mirror(db, value) != 0) {
@@ -800,6 +807,40 @@ cleanup:
 	section->siglevel = ALPM_SIG_USE_DEFAULT;
 	free(section->name);
 	section->name = NULL;
+	section->usage = 0;
+	return ret;
+}
+
+static int process_usage(alpm_list_t *values, alpm_db_usage_t *usage,
+		const char *file, int linenum)
+{
+	alpm_list_t *i;
+	alpm_db_usage_t level = *usage;
+	int ret = 0;
+
+	for(i = values; i; i = i->next) {
+		char *key = i->data;
+
+		if(strcmp(key, "Sync") == 0) {
+			level |= ALPM_DB_USAGE_SYNC;
+		} else if(strcmp(key, "Search") == 0) {
+			level |= ALPM_DB_USAGE_SEARCH;
+		} else if(strcmp(key, "Install") == 0) {
+			level |= ALPM_DB_USAGE_INSTALL;
+		} else if(strcmp(key, "Upgrade") == 0) {
+			level |= ALPM_DB_USAGE_UPGRADE;
+		} else if(strcmp(key, "All") == 0) {
+			level |= ALPM_DB_USAGE_ALL;
+		} else {
+			pm_printf(ALPM_LOG_ERROR,
+					_("config file %s, line %d: '%s' option '%s' not recognized\n"),
+					file, linenum, "Usage", key);
+			ret = 1;
+		}
+	}
+
+	*usage = level;
+
 	return ret;
 }
 
@@ -970,6 +1011,17 @@ static int _parseconfig(const char *file, struct section_t *section,
 					}
 					FREELIST(values);
 				}
+			} else if(strcmp(key, "Usage") == 0) {
+				alpm_list_t *values = NULL;
+				setrepeatingoption(value, "Usage", &values);
+				if(values) {
+					if(process_usage(values, &section->usage, file, linenum)) {
+						FREELIST(values);
+						ret = 1;
+						goto cleanup;
+					}
+					FREELIST(values);
+				}
 			} else {
 				pm_printf(ALPM_LOG_WARNING,
 						_("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
@@ -1000,6 +1052,7 @@ int parseconfig(const char *file)
 	struct section_t section;
 	memset(&section, 0, sizeof(struct section_t));
 	section.siglevel = ALPM_SIG_USE_DEFAULT;
+	section.usage = 0;
 	/* the config parse is a two-pass affair. We first parse the entire thing for
 	 * the [options] section so we can get all default and path options set.
 	 * Next, we go back and parse everything but [options]. */
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 942f765..8e90293 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -672,6 +672,7 @@ static int process_target(const char *target, int error)
 	if(targname && targname != targstring) {
 		alpm_db_t *db;
 		const char *dbname;
+		alpm_db_usage_t usage;
 
 		*targname = '\0';
 		targname++;
@@ -683,9 +684,19 @@ static int process_target(const char *target, int error)
 			ret = 1;
 			goto cleanup;
 		}
+
+		/* explicitly mark this repo as valid for installs since
+		 * a repo name was given with the target */
+		alpm_db_get_usage(db, &usage);
+		alpm_db_set_usage(db, usage|ALPM_DB_USAGE_INSTALL);
+
 		dblist = alpm_list_add(NULL, db);
 		ret = process_targname(dblist, targname, error);
 		alpm_list_free(dblist);
+
+		/* restore old usage so we don't possibly disturb later
+		 * targets */
+		alpm_db_set_usage(db, usage);
 	} else {
 		targname = targstring;
 		dblist = alpm_get_syncdbs(config->handle);
-- 
1.8.3.4



More information about the pacman-dev mailing list