[pacman-dev] [PATCH 1/2] libalpm: introduce a disabled status for repos

Dave Reisner dreisner at archlinux.org
Mon Jul 2 19:45:45 EDT 2012


Disabled repos are still sync'd on a repo refresh, but will never be
searched in when looking for package upgrades. A user can still opt to
explicitly install something from this repo by using the repo/pkgname
format for a target.

This patch introduces get/set methods for the disabled attribute on the
alpm_db_t object, alpm_db_{get,set}_disabled().

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
Dan mentioned this in IRC, and I rather liked the idea given how many times
I've accidentally updated to [staging]. Ends up being fairly non-invasive,
and doesn't require any API breakage.

 lib/libalpm/alpm.h           | 13 +++++++++++++
 lib/libalpm/db.c             | 16 ++++++++++++++++
 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 ++++++++++++++
 7 files changed, 87 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..53bf2a3 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -661,6 +661,19 @@ 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);
 
+/** Sets the disabled status of a database.
+ * @param db pointer to the package database to set the status for
+ * @param disabled a 0 (enabled) or positive integer (disabled)
+ * @return 0 on success, or -1 on error
+ */
+int alpm_db_set_disabled(alpm_db_t *db, int disabled);
+
+/** Gets the disabled status of a database.
+ * @param db pointer to the package database to get the status of
+ * @return 0 when enabled, 1 when disabled, -1 on error
+ */
+int alpm_db_get_disabled(alpm_db_t *db);
+
 /** @} */
 
 /** @addtogroup alpm_api_packages Package Functions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 8bbdc90..cc205bf 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -289,6 +289,22 @@ alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t* needles)
 	return _alpm_db_search(db, needles);
 }
 
+/** Sets the disabled status of a repo */
+int SYMEXPORT alpm_db_set_disabled(alpm_db_t *db, int disabled)
+{
+	ASSERT(db != NULL, return -1);
+	ASSERT(disabled >= 0, return -1);
+	db->disabled = !!disabled;
+	return 0;
+}
+
+/** Gets the disabled status of a repo */
+int SYMEXPORT alpm_db_get_disabled(alpm_db_t *db)
+{
+	ASSERT(db != NULL, return -1);
+	return db->disabled;
+}
+
 
 /** @} */
 
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 94659b7..76c9fa0 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;
+	int disabled;
 };
 
 
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 2a06bb0..4b953c2 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->disabled) {
+			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->disabled) {
+			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..fbf55a9 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->disabled) {
+			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->disabled) {
+				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..bd99ccc
--- /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['Disabled'] = ['true']
+
+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..be35fa7
--- /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['Disabled'] = ['true']
+
+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