[pacman-dev] [PATCH 1/2] libalpm: introduce a usage level for repos

Dave Reisner dreisner at archlinux.org
Mon Jul 2 23:16:14 EDT 2012


This defines a level of interest a user has in a repository. These are
described by the bitmask flags in the alpm_db_usage_t enum:

  ALPM_DB_USAGE_SEARCH: repo is valid for searching
  ALPM_DB_USAGE_INSTALL: repo is valid for installs (e.g. -S pkg)
  ALPM_DB_USAGE_UPGRADE: repo is valid for sysupgrades
  ALPM_DB_USAGE_ALL: all of the above are valid

Explicitly listing the contents of a repo will always be valid, and the
repo will always be refreshed appropriately on sync operations.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
@Allan: I'll see your bikeshed, and raise you a new patchset.

There's still a bit of wonky behavior in here, notably:

* Specifying only "Search" for a repo won't let you explicitly install from it.
  I'm not sure I like this. Opinions welcome.
* Specifying only "Upgrade" probably results in some odd behavior that I haven't
  found yet. Should "Upgrade" and "Install" maybe imply "Search"?
* The accessor method is probably wrong since it returns a signed integer on
  failure.

There's also definitely a need for some more tests, too. I only refactored the 2
I created for the last patchset (and only roughly). If we can hash out the wanted
behavior, I'll finish those up.

 lib/libalpm/alpm.h           | 20 ++++++++++++++++++++
 lib/libalpm/be_local.c       |  1 +
 lib/libalpm/db.c             | 20 ++++++++++++++++++++
 lib/libalpm/db.h             |  1 +
 lib/libalpm/deps.c           | 15 +++++++++++++--
 lib/libalpm/sync.c           | 15 +++++++++++++--
 test/pacman/tests/sync051.py | 17 +++++++++++++++++
 test/pacman/tests/sync052.py | 14 ++++++++++++++
 8 files changed, 99 insertions(+), 4 deletions(-)
 create mode 100644 test/pacman/tests/sync051.py
 create mode 100644 test/pacman/tests/sync052.py

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index bb792cf..381f546 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -661,6 +661,26 @@ alpm_list_t *alpm_db_get_groupcache(alpm_db_t *db);
  */
 alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles);
 
+typedef enum _alpm_db_usage_ {
+	ALPM_DB_USAGE_SEARCH = (1 << 0),
+	ALPM_DB_USAGE_INSTALL = (1 << 1),
+	ALPM_DB_USAGE_UPGRADE = (1 << 2),
+	ALPM_DB_USAGE_ALL = (1 << 3) - 1,
+} alpm_db_usage_t;
+
+/** Sets the usage of a database.
+ * @param db pointer to the package database to set the status for
+ * @param usage a bitmask of alpm_db_usage_t values
+ * @return 0 on success, or -1 on error
+ */
+int alpm_db_set_usage(alpm_db_t *db, alpm_db_usage_t usage);
+
+/** Gets the usage of a database.
+ * @param db pointer to the package database to get the status of
+ * @return a bitmask described by alpm_db_usage_t, or -1 on error
+ */
+alpm_db_usage_t alpm_db_get_usage(alpm_db_t *db);
+
 /** @} */
 
 /** @addtogroup alpm_api_packages Package Functions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index ee805b9..47843ad 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -1011,6 +1011,7 @@ alpm_db_t *_alpm_db_register_local(alpm_handle_t *handle)
 	}
 	db->ops = &local_db_ops;
 	db->handle = handle;
+	db->usage = ALPM_DB_USAGE_ALL;
 
 	if(local_db_validate(db)) {
 		/* pm_errno set in local_db_validate() */
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 8bbdc90..584698f 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -289,6 +289,21 @@ alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t* needles)
 	return _alpm_db_search(db, needles);
 }
 
+/** Sets the usage bitmask for a repo */
+int SYMEXPORT alpm_db_set_usage(alpm_db_t *db, alpm_db_usage_t usage)
+{
+	ASSERT(db != NULL, return -1);
+	db->usage = usage;
+	return 0;
+}
+
+/** Gets the usage bitmask for a repo */
+alpm_db_usage_t SYMEXPORT alpm_db_get_usage(alpm_db_t *db)
+{
+	ASSERT(db != NULL, return -1);
+	return db->usage;
+}
+
 
 /** @} */
 
@@ -362,6 +377,11 @@ alpm_list_t *_alpm_db_search(alpm_db_t *db, const alpm_list_t *needles)
 {
 	const alpm_list_t *i, *j, *k;
 	alpm_list_t *ret = NULL;
+
+	if(!(db->usage & ALPM_DB_USAGE_SEARCH)) {
+		return NULL;
+	}
+
 	/* copy the pkgcache- we will free the list var after each needle */
 	alpm_list_t *list = alpm_list_copy(_alpm_db_get_pkgcache(db));
 
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 94659b7..c1067cb 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -73,6 +73,7 @@ struct __alpm_db_t {
 	/* flags determining validity, local, loaded caches, etc. */
 	enum _alpm_dbstatus_t status;
 	alpm_siglevel_t siglevel;
+	alpm_db_usage_t usage;
 };
 
 
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 2a06bb0..6bfc579 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -589,7 +589,14 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
 
 	/* 1. literals */
 	for(i = dbs; i; i = i->next) {
-		alpm_pkg_t *pkg = _alpm_db_get_pkgfromcache(i->data, dep->name);
+		alpm_pkg_t *pkg;
+		alpm_db_t *db = i->data;
+
+		if(!(db->usage & (ALPM_DB_USAGE_INSTALL|ALPM_DB_USAGE_UPGRADE))) {
+			continue;
+		}
+
+		pkg = _alpm_db_get_pkgfromcache(db, dep->name);
 		if(pkg && _alpm_depcmp_literal(pkg, dep)
 				&& !_alpm_pkg_find(excluding, pkg->name)) {
 			if(_alpm_pkg_should_ignore(handle, pkg)) {
@@ -611,7 +618,11 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
 	}
 	/* 2. satisfiers (skip literals here) */
 	for(i = dbs; i; i = i->next) {
-		for(j = _alpm_db_get_pkgcache(i->data); j; j = j->next) {
+		alpm_db_t *db = i->data;
+		if(!(db->usage & (ALPM_DB_USAGE_INSTALL|ALPM_DB_USAGE_UPGRADE))) {
+			continue;
+		}
+		for(j = _alpm_db_get_pkgcache(db); j; j = j->next) {
 			alpm_pkg_t *pkg = j->data;
 			/* with hash != hash, we can even skip the strcmp() as we know they can't
 			 * possibly be the same string */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 66f7ed1..b7809ee 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -60,7 +60,12 @@ alpm_pkg_t SYMEXPORT *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_syn
 	pkg->handle->pm_errno = 0;
 
 	for(i = dbs_sync; !spkg && i; i = i->next) {
-		spkg = _alpm_db_get_pkgfromcache(i->data, pkg->name);
+		alpm_db_t *db = i->data;
+		if(!(db->usage & ALPM_DB_USAGE_SEARCH)) {
+			continue;
+		}
+
+		spkg = _alpm_db_get_pkgfromcache(db, pkg->name);
 	}
 
 	if(spkg == NULL) {
@@ -212,8 +217,14 @@ int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade)
 		for(j = handle->dbs_sync; j; j = j->next) {
 			alpm_db_t *sdb = j->data;
 			/* Check sdb */
-			alpm_pkg_t *spkg = _alpm_db_get_pkgfromcache(sdb, lpkg->name);
+			alpm_pkg_t *spkg;
 			int literal_upgrade = 0;
+
+			if(!(sdb->usage & ALPM_DB_USAGE_UPGRADE)) {
+				continue;
+			}
+
+			spkg = _alpm_db_get_pkgfromcache(sdb, lpkg->name);
 			if(spkg) {
 				literal_upgrade = check_literal(handle, lpkg, spkg, enable_downgrade);
 				if(literal_upgrade) {
diff --git a/test/pacman/tests/sync051.py b/test/pacman/tests/sync051.py
new file mode 100644
index 0000000..8908dd9
--- /dev/null
+++ b/test/pacman/tests/sync051.py
@@ -0,0 +1,17 @@
+self.description = "upgrade a package with a disabled repo"
+
+sp = pmpkg("dummy", "2.0-1")
+self.addpkg2db("syncdisabled", sp)
+
+sp = pmpkg("dummy", "1.0-2")
+self.addpkg2db("sync", sp)
+
+lp = pmpkg("dummy", "1.0-1")
+self.addpkg2db("local", lp)
+
+self.args = "-S %s" % sp.name
+
+self.db['syncdisabled'].option['Usage'] = ['Search']
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=dummy|1.0-2")
diff --git a/test/pacman/tests/sync052.py b/test/pacman/tests/sync052.py
new file mode 100644
index 0000000..6ac8fe2
--- /dev/null
+++ b/test/pacman/tests/sync052.py
@@ -0,0 +1,14 @@
+self.description = "sysupgrade with a disabled repo"
+
+sp = pmpkg("dummy", "1.0-2")
+self.addpkg2db("sync", sp)
+
+lp = pmpkg("dummy", "1.0-1")
+self.addpkg2db("local", lp)
+
+self.args = "-Syu"
+
+self.db['sync'].option['Usage'] = ['Search']
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=dummy|1.0-1")
-- 
1.7.11.1



More information about the pacman-dev mailing list