[pacman-dev] [PATCH] sync.c: download packages before starting commit

Andrew Gregory andrew.gregory.8 at gmail.com
Sat Oct 11 08:49:29 UTC 2014


download_files sets the transaction state to STATE_DOWNLOADING.
Modifying the state after it has already been set to STATE_COMMITTING
created a brief window where SIGINT would fail to interrupt the process
and caused interrupted downloads to result in a 'transaction started'
message in the log with no matching transaction end.

Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
 lib/libalpm/sync.c  | 11 ++++++++---
 lib/libalpm/sync.h  |  1 +
 lib/libalpm/trans.c | 10 ++++++++++
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 9fe4eff..c513b6b 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -1263,13 +1263,12 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data,
 	return 0;
 }
 
-int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
+int _alpm_sync_load(alpm_handle_t *handle, alpm_list_t **data)
 {
 	alpm_list_t *i, *deltas = NULL;
 	size_t total = 0;
 	uint64_t total_bytes = 0;
 	alpm_trans_t *trans = handle->trans;
-	alpm_event_t event;
 
 	if(download_files(handle, &deltas)) {
 		alpm_list_free(deltas);
@@ -1318,7 +1317,13 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
 		return -1;
 	}
 
-	trans->state = STATE_COMMITING;
+	return 0;
+}
+
+int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
+{
+	alpm_trans_t *trans = handle->trans;
+	alpm_event_t event;
 
 	/* fileconflict check */
 	if(!(trans->flags & ALPM_TRANS_FLAG_DBONLY)) {
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h
index f25e450..c15d348 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/sync.h
@@ -25,6 +25,7 @@
 #include "alpm.h"
 
 int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data);
+int _alpm_sync_load(alpm_handle_t *handle, alpm_list_t **data);
 int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data);
 
 #endif /* _ALPM_SYNC_H */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index aebd8dd..7cdb096 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -175,6 +175,16 @@ int SYMEXPORT alpm_trans_commit(alpm_handle_t *handle, alpm_list_t **data)
 		return 0;
 	}
 
+	if(trans->add) {
+		if(_alpm_sync_load(handle, data) != 0) {
+			/* pm_errno is set by _alpm_sync_load() */
+			return -1;
+		}
+		if(trans->flags & ALPM_TRANS_FLAG_DOWNLOADONLY) {
+			return 0;
+		}
+	}
+
 	trans->state = STATE_COMMITING;
 
 	alpm_logaction(handle, ALPM_CALLER_PREFIX, "transaction started\n");
-- 
2.1.2


More information about the pacman-dev mailing list