[pacman-dev] [PATCH 8/8] Add events _PKGDOWNLOAD_{START, DONE, FAILED}

Olivier Brunel jjk at jjacky.com
Mon Dec 2 15:45:20 EST 2013


These will be emmitted when download a package file from a repository,
indicating that the download starts, and whether it was successfull or
not.

Note that when multiple servers are available, no event is emmitted when
switching to another server.

(This doesn't apply to alpm_fetch_pkgurl(), but since it is called by
the frontend, it shouldn't have problems knowing when the download
starts and when it ends.)

Signed-off-by: Olivier Brunel <jjk at jjacky.com>
---
 lib/libalpm/alpm.h    | 16 ++++++++++++++++
 lib/libalpm/sync.c    |  9 +++++++++
 src/pacman/callback.c |  4 ++++
 3 files changed, 29 insertions(+)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index a61a712..f146ab1 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -322,6 +322,15 @@ typedef enum _alpm_event_type_t {
 	ALPM_EVENT_RETRIEVE_DONE,
 	/** Not all files were successfully downloaded from a repository. */
 	ALPM_EVENT_RETRIEVE_FAILED,
+	/** A file will be downloaded from a repository; See alpm_event_pkgdownload_t
+	 * for arguments */
+	ALPM_EVENT_PKGDOWNLOAD_START,
+	/** A file was downloaded from a repository; See alpm_event_pkgdownload_t
+	 * for arguments */
+	ALPM_EVENT_PKGDOWNLOAD_DONE,
+	/** A file failed to be downloaded from a repository; See
+	 * alpm_event_pkgdownload_t for arguments */
+	ALPM_EVENT_PKGDOWNLOAD_FAILED,
 	/** Disk space usage will be computed for a package. */
 	ALPM_EVENT_DISKSPACE_START,
 	/** Disk space usage was computed for a package. */
@@ -467,6 +476,13 @@ typedef struct _alpm_event_pacorig_created_t {
 	const char *oldfile;
 } alpm_event_pacorig_created_t;
 
+typedef struct _alpm_event_pkgdownload_t {
+	/** Type of event. */
+	alpm_event_type_t type;
+	/** Name of the file */
+	const char *file;
+} alpm_event_pkgdownload_t;
+
 /** Event callback. */
 typedef void (*alpm_cb_event)(alpm_event_t *);
 
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 8046ce5..3ed10c0 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -894,11 +894,16 @@ static int find_dl_candidates(alpm_db_t *repo, alpm_list_t **files, alpm_list_t
 static int download_single_file(alpm_handle_t *handle, struct dload_payload *payload,
 		const char *cachedir)
 {
+	alpm_event_pkgdownload_t event = {
+		.type = ALPM_EVENT_PKGDOWNLOAD_START,
+		.file = payload->remote_name
+	};
 	const alpm_list_t *server;
 
 	payload->handle = handle;
 	payload->allow_resume = 1;
 
+	EVENT(handle, &event);
 	for(server = payload->servers; server; server = server->next) {
 		const char *server_url = server->data;
 		size_t len;
@@ -909,6 +914,8 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay
 		snprintf(payload->fileurl, len, "%s/%s", server_url, payload->remote_name);
 
 		if(_alpm_download(payload, cachedir, NULL, NULL) != -1) {
+			event.type = ALPM_EVENT_PKGDOWNLOAD_DONE;
+			EVENT(handle, &event);
 			return 0;
 		}
 
@@ -916,6 +923,8 @@ static int download_single_file(alpm_handle_t *handle, struct dload_payload *pay
 		payload->unlink_on_fail = 0;
 	}
 
+	event.type = ALPM_EVENT_PKGDOWNLOAD_FAILED;
+	EVENT(handle, &event);
 	return -1;
 }
 
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index e4517f8..2a89d30 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -350,6 +350,10 @@ void cb_event(alpm_event_t *event)
 		case ALPM_EVENT_DISKSPACE_DONE:
 		case ALPM_EVENT_RETRIEVE_DONE:
 		case ALPM_EVENT_RETRIEVE_FAILED:
+		/* we can safely ignore those as well */
+		case ALPM_EVENT_PKGDOWNLOAD_START:
+		case ALPM_EVENT_PKGDOWNLOAD_DONE:
+		case ALPM_EVENT_PKGDOWNLOAD_FAILED:
 			/* nothing */
 			break;
 	}
-- 
1.8.4.2



More information about the pacman-dev mailing list