[pacman-dev] [PATCH] trans_prepare: always sort trans->remove by deps

Andrew Gregory andrew.gregory.8 at gmail.com
Wed Dec 11 11:58:28 EST 2013


Packages can be removed during a sync transaction either directly or
due to conflicts and need to be sorted.

Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
 lib/libalpm/remove.c         |  7 -------
 lib/libalpm/sync.c           |  5 -----
 lib/libalpm/trans.c          | 16 ++++++++++++++++
 test/pacman/tests/TESTS      |  1 +
 test/pacman/tests/sync046.py | 29 +++++++++++++++++++++++++++++
 5 files changed, 46 insertions(+), 12 deletions(-)
 create mode 100644 test/pacman/tests/sync046.py

diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 9417a61..6c50ab3 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -240,13 +240,6 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
 		}
 	}
 
-	/* re-order w.r.t. dependencies */
-	_alpm_log(handle, ALPM_LOG_DEBUG, "sorting by dependencies\n");
-	lp = _alpm_sortbydeps(handle, trans->remove, NULL, 1);
-	/* free the old alltargs */
-	alpm_list_free(trans->remove);
-	trans->remove = lp;
-
 	/* -Rcs == -Rc then -Rs */
 	if((trans->flags & ALPM_TRANS_FLAG_CASCADE)
 			&& (trans->flags & ALPM_TRANS_FLAG_RECURSE)) {
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 7dbb8a0..ba71d89 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -625,11 +625,6 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
 			}
 			goto cleanup;
 		}
-
-		/* re-order w.r.t. dependencies */
-		alpm_list_t *add_orig = trans->add;
-		trans->add = _alpm_sortbydeps(handle, add_orig, trans->remove, 0);
-		alpm_list_free(add_orig);
 	}
 	for(i = trans->add; i; i = i->next) {
 		/* update download size field */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index a795a1f..6ace823 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -39,6 +39,7 @@
 #include "remove.h"
 #include "sync.h"
 #include "alpm.h"
+#include "deps.h"
 
 /** \addtogroup alpm_trans Transaction Functions
  * @brief Functions to manipulate libalpm transactions
@@ -134,6 +135,21 @@ int SYMEXPORT alpm_trans_prepare(alpm_handle_t *handle, alpm_list_t **data)
 		}
 	}
 
+
+	if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
+		_alpm_log(handle, ALPM_LOG_DEBUG, "sorting by dependencies\n");
+		if(trans->add) {
+			alpm_list_t *add_orig = trans->add;
+			trans->add = _alpm_sortbydeps(handle, add_orig, trans->remove, 0);
+			alpm_list_free(add_orig);
+		}
+		if(trans->remove) {
+			alpm_list_t *rem_orig = trans->remove;
+			trans->remove = _alpm_sortbydeps(handle, rem_orig, NULL, 1);
+			alpm_list_free(rem_orig);
+		}
+	}
+
 	trans->state = STATE_PREPARED;
 
 	return 0;
diff --git a/test/pacman/tests/TESTS b/test/pacman/tests/TESTS
index fc6a7e8..f52a1f7 100644
--- a/test/pacman/tests/TESTS
+++ b/test/pacman/tests/TESTS
@@ -158,6 +158,7 @@ TESTS += test/pacman/tests/sync042.py
 TESTS += test/pacman/tests/sync043.py
 TESTS += test/pacman/tests/sync044.py
 TESTS += test/pacman/tests/sync045.py
+TESTS += test/pacman/tests/sync046.py
 TESTS += test/pacman/tests/sync050.py
 TESTS += test/pacman/tests/sync051.py
 TESTS += test/pacman/tests/sync052.py
diff --git a/test/pacman/tests/sync046.py b/test/pacman/tests/sync046.py
new file mode 100644
index 0000000..63e8cc3
--- /dev/null
+++ b/test/pacman/tests/sync046.py
@@ -0,0 +1,29 @@
+self.description = "Install a sync package with interdependent conflicts"
+
+sp = pmpkg("pkg1")
+sp.conflicts = ["pkg2", "pkg3", "pkg4"]
+self.addpkg2db("sync", sp);
+
+lp1 = pmpkg("pkg2")
+lp1.depends = ["pkg3"]
+lp1.install['pre_remove'] = "[ -f pkg3file ] && echo '' > pkg2ok"
+self.addpkg2db("local", lp1);
+
+lp2 = pmpkg("pkg3")
+lp2.files = ["pkg3file"]
+self.addpkg2db("local", lp2);
+
+lp3 = pmpkg("pkg4")
+lp3.depends = ["pkg3"]
+lp3.install['pre_remove'] = "[ -f pkg3file ] && echo '' > pkg4ok"
+self.addpkg2db("local", lp3);
+
+self.args = "-S %s --ask=4" % sp.name
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_EXIST=pkg1")
+self.addrule("!PKG_EXIST=pkg2")
+self.addrule("!PKG_EXIST=pkg3")
+self.addrule("!PKG_EXIST=pkg4")
+self.addrule("FILE_EXIST=pkg2ok")
+self.addrule("FILE_EXIST=pkg4ok")
-- 
1.8.5.1



More information about the pacman-dev mailing list