[pacman-dev] [PATCH] alpm: Add events for creation of pacnew/pacorig files

Allan McRae allan at archlinux.org
Fri Nov 15 06:28:05 EST 2013


On 10/11/13 04:49, Olivier Brunel wrote:
> Signed-off-by: Olivier Brunel <jjk at jjacky.com>
> ---
> Hey,
> 
> Some background regarding this: I've written a little tool (kalu, [1]) which is
> an upgrade notifier, and also features a GUI/frontend for the sysupgrade (-Syu)
> operation.
> 
> Whenever there was a pacnew installed, I would open a terminal and run vimdiff
> on the files; I would also wonder if it wouldn't be nice to have a third file
> featured, the "original" one (i.e. from the previous package). And so I started
> wondering about kalu making a list of all pacnew files created during the
> upgrade, as well as the name & version of the old package, so that I could use a
> little script to extract the file and start the 3-way diff.
> 
> (kalu allows to execute one or more command lines after the sysupgrade
> completed, so this list is just a variable parsed on said cmdlines.)
> 
> This all works well, but to make that list, kalu would have to e.g. use a regex
> to extract the pacnew filenames from ALPM's warnings, and that's just not a very
> good or reliable thing, especially when you know such warnings are translated.
> 
> Hence, why adding a couple events (there's pacorig as well) in ALPM makes
> everything much better & simpler; And knowing about such events could be useful
> to some frontends, even though pacman obviously has no use for it (atm).
> 
> So, I'm hoping you'd be willing to merge this.
> 
> Thanks,
> -j
> 
> [1] http://jjacky.com/kalu

I agree the backend should report this to the frontend.   In fact, I
would like the backend to be completely quiet and report everything to
the frontend.

Lets look at what your patch currently does:

alpm_pkg_t *arr[2] = { oldpkg, newpkg };
EVENT(handle, ALPM_EVENT_PACNEW, arr, newpath);

First the passed path.  I think passing filename (e.g. /etc/pacman.conf)
rather than newpath (e.g. /etc/pacman.conf.pacsave) is the better
approach for that.  It requires less to output a ".pacsave" than to
remove one.

Now I am not sure about the oldpkg/newpkg in an array passing.  I think
just passing pkgname is a reasonable compromise.  I guess the frontend
then can grab the old package version easily enough.

Allan


> 
>  lib/libalpm/add.c     |  3 +++
>  lib/libalpm/alpm.h    | 10 +++++++++-
>  src/pacman/callback.c |  3 +++
>  3 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
> index ac4e36a..e5eca97 100644
> --- a/lib/libalpm/add.c
> +++ b/lib/libalpm/add.c
> @@ -363,10 +363,12 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
>  				if(try_rename(handle, checkfile, newpath)) {
>  					errors++;
>  				} else {
> +					alpm_pkg_t *arr[2] = { oldpkg, newpkg };
>  					_alpm_log(handle, ALPM_LOG_WARNING, _("%s installed as %s\n"),
>  							filename, newpath);
>  					alpm_logaction(handle, ALPM_CALLER_PREFIX,
>  							"warning: %s installed as %s\n", filename, newpath);
> +					EVENT(handle, ALPM_EVENT_PACNEW, arr, newpath);
>  				}
>  
>  				free(newpath);
> @@ -395,6 +397,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
>  								_("%s saved as %s\n"), filename, newpath);
>  						alpm_logaction(handle, ALPM_CALLER_PREFIX,
>  								"warning: %s saved as %s\n", filename, newpath);
> +						EVENT(handle, ALPM_EVENT_PACORIG, newpkg, newpath);
>  					}
>  				}
>  
> diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
> index 2c8c1e6..c4f772d 100644
> --- a/lib/libalpm/alpm.h
> +++ b/lib/libalpm/alpm.h
> @@ -387,7 +387,15 @@ typedef enum _alpm_event_t {
>  	/** Downloading missing keys into keyring. */
>  	ALPM_EVENT_KEY_DOWNLOAD_START,
>  	/** Key downloading is finished. */
> -	ALPM_EVENT_KEY_DOWNLOAD_DONE
> +	ALPM_EVENT_KEY_DOWNLOAD_DONE,
> +	/** A .pacnew file was installed
> +	 * An array of packages (current/old one, and installed/new one) and the
> +	 * name of the pacnew file are passed to the callback */
> +	ALPM_EVENT_PACNEW,
> +	/** A .pacorig file was created
> +	 * The installed/new package and the name of the pacorig file are passed to
> +	 * the callback */
> +	ALPM_EVENT_PACORIG
>  } alpm_event_t;
>  
>  /** Event callback */
> diff --git a/src/pacman/callback.c b/src/pacman/callback.c
> index 36531a2..0fc35f6 100644
> --- a/src/pacman/callback.c
> +++ b/src/pacman/callback.c
> @@ -297,6 +297,9 @@ void cb_event(alpm_event_t event, void *data1, void *data2)
>  		case ALPM_EVENT_DELTA_INTEGRITY_DONE:
>  		case ALPM_EVENT_DELTA_PATCHES_DONE:
>  		case ALPM_EVENT_DISKSPACE_DONE:
> +		/* events of creation of .pacnew/.pacorig files */
> +		case ALPM_EVENT_PACNEW:
> +		case ALPM_EVENT_PACORIG:
>  			/* nothing */
>  			break;
>  	}
> 



More information about the pacman-dev mailing list