[pacman-dev] [PATCH] Move -Sp implementation to the front-end

Nagy Gabor ngaba at bibl.u-szeged.hu
Sun Aug 17 13:00:57 EDT 2008


From b6518fd82b2d3fb9dd0dc2541eb5010f2ac80870 Mon Sep 17 00:00:00 2001
From: Nagy Gabor <ngaba at bibl.u-szeged.hu>
Date: Sun, 17 Aug 2008 18:42:35 +0200
Subject: [PATCH] Move -Sp implementation to the front-end

This patch kills one of our hackish pseudo transactions: PRINTURIS.
(The other one is -Sw)

From now on, front-end must not call trans_commit in case of -Sp,
it should print the uris of target packages "by hand" instead.

PRINTURIS flag was removed, NOCONFLICT flag can be passed to skip
conflict checks.

Signed-off-by: Nagy Gabor <ngaba at bibl.u-szeged.hu>
---
 lib/libalpm/alpm.h    |    8 ++------
 lib/libalpm/sync.c    |   46 +++++++++++++++++++---------------------------
 src/pacman/callback.c |    3 ---
 src/pacman/conf.h     |    1 +
 src/pacman/pacman.c   |    3 ++-
 src/pacman/sync.c     |   41 +++++++++++++++++++++++++----------------
 6 files changed, 49 insertions(+), 53 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 4ea03a9..71c08e4 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -282,7 +282,7 @@ typedef enum _pmtransflag_t {
 	PM_TRANS_FLAG_DOWNLOADONLY = 0x200,
 	PM_TRANS_FLAG_NOSCRIPTLET = 0x400,
 	PM_TRANS_FLAG_NOCONFLICTS = 0x800,
-	PM_TRANS_FLAG_PRINTURIS = 0x1000,
+	/* 0x1000 flag can go here */
 	PM_TRANS_FLAG_NEEDED = 0x2000,
 	PM_TRANS_FLAG_ALLEXPLICIT = 0x4000,
 	PM_TRANS_FLAG_UNNEEDED = 0x8000,
@@ -364,14 +364,10 @@ typedef enum _pmtransevt_t {
 	 * A line of text is passed to the callback.
 	 */
 	PM_TRANS_EVT_SCRIPTLET_INFO,
-	/** Print URI.
-	 * The database's URI and the package's filename are passed to the callback.
-	 */
-	PM_TRANS_EVT_PRINTURI,
 	/** Files will be downloaded from a repository.
 	 * The repository's tree name is passed to the callback.
 	 */
-	PM_TRANS_EVT_RETRIEVE_START,
+	PM_TRANS_EVT_RETRIEVE_START
 } pmtransevt_t;
 /*@}*/
 
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 7a577a1..d85c2dc 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -486,7 +486,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
 	}
 
 	/* We don't care about conflicts if we're just printing uris */
-	if(!(trans->flags & (PM_TRANS_FLAG_NOCONFLICTS | PM_TRANS_FLAG_PRINTURIS))) {
+	if(!(trans->flags & PM_TRANS_FLAG_NOCONFLICTS)) {
 		/* check for inter-conflicts and whatnot */
 		EVENT(trans, PM_TRANS_EVT_INTERCONFLICTS_START, NULL, NULL);
 
@@ -826,32 +826,27 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
 
 				fname = alpm_pkg_get_filename(spkg);
 				ASSERT(fname != NULL, RET_ERR(PM_ERR_PKG_INVALID_NAME, -1));
-				if(trans->flags & PM_TRANS_FLAG_PRINTURIS) {
-					EVENT(trans, PM_TRANS_EVT_PRINTURI, (char *)alpm_db_get_url(current),
-							(char *)fname);
-				} else {
-					if(spkg->download_size != 0) {
-						alpm_list_t *delta_path = spkg->delta_path;
-						if(delta_path) {
-							alpm_list_t *dlts = NULL;
-
-							for(dlts = delta_path; dlts; dlts = dlts->next) {
-								pmdelta_t *d = dlts->data;
-
-								if(d->download_size != 0) {
-									/* add the delta filename to the download list if
-									 * it's not in the cache */
-									files = alpm_list_add(files, strdup(d->delta));
-								}
-
-								/* keep a list of the delta files for md5sums */
-								deltas = alpm_list_add(deltas, d);
+				if(spkg->download_size != 0) {
+					alpm_list_t *delta_path = spkg->delta_path;
+					if(delta_path) {
+						alpm_list_t *dlts = NULL;
+
+						for(dlts = delta_path; dlts; dlts = dlts->next) {
+							pmdelta_t *d = dlts->data;
+
+							if(d->download_size != 0) {
+								/* add the delta filename to the download list if
+								 * it's not in the cache */
+								files = alpm_list_add(files, strdup(d->delta));
 							}
 
-						} else {
-							/* not using deltas, so add the file to the download list */
-							files = alpm_list_add(files, strdup(fname));
+							/* keep a list of the delta files for md5sums */
+							deltas = alpm_list_add(deltas, d);
 						}
+
+					} else {
+						/* not using deltas, so add the file to the download list */
+						files = alpm_list_add(files, strdup(fname));
 					}
 				}
 			}
@@ -868,9 +863,6 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
 			FREELIST(files);
 		}
 	}
-	if(trans->flags & PM_TRANS_FLAG_PRINTURIS) {
-		return(0);
-	}
 
 	/* clear out value to let callback know we are done */
 	if(handle->totaldlcb) {
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 30e34a9..9f4b52b 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -226,9 +226,6 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2)
 		case PM_TRANS_EVT_SCRIPTLET_INFO:
 			printf("%s", (char*)data1);
 			break;
-		case PM_TRANS_EVT_PRINTURI:
-			printf("%s/%s\n", (char*)data1, (char*)data2);
-			break;
 		case PM_TRANS_EVT_RETRIEVE_START:
 			printf(_(":: Retrieving packages from %s...\n"), (char*)data1);
 			break;
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 9d2318d..8ea6662 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -57,6 +57,7 @@ typedef struct __config_t {
 	unsigned short op_s_sync;
 	unsigned short op_s_search;
 	unsigned short op_s_upgrade;
+	unsigned short op_s_printuris;
 
 	unsigned short group;
 	pmtransflag_t flags;
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 8b8698b..b828cfb 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -461,7 +461,8 @@ static int parseargs(int argc, char *argv[])
 			case 'o': config->op_q_owns = 1; break;
 			case 'p':
 				config->op_q_isfile = 1;
-				config->flags |= PM_TRANS_FLAG_PRINTURIS;
+				config->op_s_printuris = 1;
+				config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
 				break;
 			case 'q':
 				config->quiet = 1;
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index ae3f523..7bb9ada 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -666,23 +666,32 @@ static int sync_trans(alpm_list_t *targets)
 		goto cleanup;
 	}
 
-	if(!(alpm_trans_get_flags() & PM_TRANS_FLAG_PRINTURIS)) {
-		int confirm;
+	/* Step 3: actually perform the operation */
+	if(config->op_s_printuris) {
+		/* print uris */
+		alpm_list_t *i;
+		for(i = packages; i; i = alpm_list_next(i)) {
+			pmpkg_t *pkg = alpm_sync_get_pkg((pmsyncpkg_t *)alpm_list_getdata(i));
+			pmdb_t *db = alpm_pkg_get_db(pkg);
+			printf("%s/%s\n", alpm_db_get_url(db), alpm_pkg_get_filename(pkg));
+		}
+		/* we are done */
+		goto cleanup;
+	}
 
-		display_synctargets(packages);
-		printf("\n");
+	display_synctargets(packages);
+	printf("\n");
 
-		if(config->op_s_downloadonly) {
-			confirm = yesno(1, _("Proceed with download?"));
-		} else {
-			confirm = yesno(1, _("Proceed with installation?"));
-		}
-		if(!confirm) {
-			goto cleanup;
-		}
-	}/* else 'print uris' requested.  We're done at this point */
+	int confirm;
+	if(config->op_s_downloadonly) {
+		confirm = yesno(1, _("Proceed with download?"));
+	} else {
+		confirm = yesno(1, _("Proceed with installation?"));
+	}
+	if(!confirm) {
+		goto cleanup;
+	}
 
-	/* Step 3: actually perform the installation */
 	if(alpm_trans_commit(&data) == -1) {
 		pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
 		        alpm_strerrorlast());
@@ -739,7 +748,7 @@ int pacman_sync(alpm_list_t *targets)
 	alpm_list_t *sync_dbs = NULL;
 
 	/* Display only errors with -Sp and -Sw operations */
-	if(config->flags & (PM_TRANS_FLAG_DOWNLOADONLY | PM_TRANS_FLAG_PRINTURIS)) {
+	if((config->flags & PM_TRANS_FLAG_DOWNLOADONLY) || config->op_s_printuris) {
 		config->logmask &= ~PM_LOG_WARNING;
 	}
 
@@ -811,7 +820,7 @@ int pacman_sync(alpm_list_t *targets)
 	}
 
 	alpm_list_t *targs = alpm_list_strdup(targets);
-	if(!(config->flags & (PM_TRANS_FLAG_DOWNLOADONLY | PM_TRANS_FLAG_PRINTURIS))) {
+	if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY) && !config->op_s_printuris) {
 		/* check for newer versions of packages to be upgraded first */
 		alpm_list_t *packages = syncfirst();
 		if(packages) {
-- 
1.5.6.5




More information about the pacman-dev mailing list