[pacman-dev] [PATCH] Add remove counterparts to alpm_option_add_* functions

Nagy Gabor ngaba at bibl.u-szeged.hu
Sat Dec 22 08:19:25 EST 2007


> From: Allan McRae <allan.mcrae at qimr.edu.au>
> To: Discussion list for pacman development <pacman-dev at archlinux.org>
> Subject: [pacman-dev] [PATCH] Add remove counterparts to
> alpm_option_add_* functions Date: Sat, 22 Dec 2007 21:29:22 +1000
> Reply-To: Discussion list for pacman development
> <pacman-dev at archlinux.org> User-Agent: Thunderbird 2.0.0.9
> (X11/20071213)
> 
> 
> 
> >From 0f9238992b6edd47efaf9b6647f416aab7b679f4 Mon Sep 17 00:00:00
> >2001  
> From: Allan McRae <mcrae_allan at hotmail.com>
> Date: Sat, 22 Dec 2007 21:28:08 +1000
> Subject: [PATCH] Add remove counterparts to alpm_option_add_*
> functions
> 
> Fixes FS#7428. Added functions to remove cachedir, noupgrade,
> noextract, ignorepkg, holdpkg and ignoregrp.
> 
> Signed-off-by: Allan McRae <mcrae_allan at hotmail.com>
> ---
>  lib/libalpm/alpm.h   |    6 +++++
>  lib/libalpm/handle.c |   55
> ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed,
> 61 insertions(+), 0 deletions(-)
> 
> diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
> index 3a484be..e2d90fb 100644
> --- a/lib/libalpm/alpm.h
> +++ b/lib/libalpm/alpm.h
> @@ -104,6 +104,7 @@ int alpm_option_set_dbpath(const char *dbpath);
>  alpm_list_t *alpm_option_get_cachedirs();
>  int alpm_option_add_cachedir(const char *cachedir);
>  void alpm_option_set_cachedirs(alpm_list_t *cachedirs);
> +void alpm_option_remove_cachedir(const char *cachedir);
>  
>  const char *alpm_option_get_logfile();
>  int alpm_option_set_logfile(const char *logfile);
> @@ -117,22 +118,27 @@ void alpm_option_set_usesyslog(unsigned short
> usesyslog); alpm_list_t *alpm_option_get_noupgrades();
>  void alpm_option_add_noupgrade(const char *pkg);
>  void alpm_option_set_noupgrades(alpm_list_t *noupgrade);
> +void alpm_option_remove_noupgrade(const char *pkg);
>  
>  alpm_list_t *alpm_option_get_noextracts();
>  void alpm_option_add_noextract(const char *pkg);
>  void alpm_option_set_noextracts(alpm_list_t *noextract);
> +void alpm_option_remove_noextract(const char *pkg);
>  
>  alpm_list_t *alpm_option_get_ignorepkgs();
>  void alpm_option_add_ignorepkg(const char *pkg);
>  void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs);
> +void alpm_option_remove_ignorepkg(const char *pkg);
>  
>  alpm_list_t *alpm_option_get_holdpkgs();
>  void alpm_option_add_holdpkg(const char *pkg);
>  void alpm_option_set_holdpkgs(alpm_list_t *holdpkgs);
> +void alpm_option_remove_holdpkg(const char *pkg);
>  
>  alpm_list_t *alpm_option_get_ignoregrps();
>  void alpm_option_add_ignoregrp(const char *grp);
>  void alpm_option_set_ignoregrps(alpm_list_t *ignoregrps);
> +void alpm_option_remove_ignoregrp(const char *grp);
>  
>  time_t alpm_option_get_upgradedelay();
>  void alpm_option_set_upgradedelay(time_t delay);
> diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
> index ab6fc7e..4359c91 100644
> --- a/lib/libalpm/handle.c
> +++ b/lib/libalpm/handle.c
> @@ -395,6 +395,26 @@ void SYMEXPORT
> alpm_option_set_cachedirs(alpm_list_t *cachedirs) if(cachedirs)
> handle->cachedirs = cachedirs; }
>  
> +void SYMEXPORT alpm_option_remove_cachedir(const char *cachedir)
> +{
> +	void *vdata;
> +	char *newcachedir;
> +	size_t cachedirlen;
> +	
> +	/* verify cachedir ends in a '/' */
> +	cachedirlen = strlen(cachedir);
> +	if(cachedir[cachedirlen-1] != '/') {
> +		cachedirlen += 1;
> +	}
> +	newcachedir = calloc(cachedirlen + 1, sizeof(char));
> +	strncpy(newcachedir, cachedir, cachedirlen);
> +	newcachedir[cachedirlen-1] = '/';
> +		
> +	handle->cachedirs = alpm_list_remove(handle->cachedirs,
> newcachedir,
> +		_alpm_str_cmp, &vdata);
> +	
> +}
> +
>  int SYMEXPORT alpm_option_set_logfile(const char *logfile)
>  {
>  	char *oldlogfile = handle->logfile;
> @@ -436,6 +456,13 @@ void SYMEXPORT
> alpm_option_set_noupgrades(alpm_list_t *noupgrade) if(noupgrade)
> handle->noupgrade = noupgrade; }
>  
> +void SYMEXPORT alpm_option_remove_noupgrade(const char *pkg)
> +{
> +	void *vdata;
> +	handle->noupgrade = alpm_list_remove(handle->noupgrade,
> strdup(pkg), 
> +		_alpm_str_cmp, &vdata);
> +}
> +
>  void SYMEXPORT alpm_option_add_noextract(const char *pkg)
>  {
>  	handle->noextract = alpm_list_add(handle->noextract,
> strdup(pkg)); @@ -447,6 +474,13 @@ void SYMEXPORT
> alpm_option_set_noextracts(alpm_list_t *noextract) if(noextract)
> handle->noextract = noextract; }
>  
> +void SYMEXPORT alpm_option_remove_noextract(const char *pkg)
> +{
> +	void *vdata;
> +	handle->noextract = alpm_list_remove(handle->noextract,
> strdup(pkg), 
> +		_alpm_str_cmp, &vdata);
> +}
> +
>  void SYMEXPORT alpm_option_add_ignorepkg(const char *pkg)
>  {
>  	handle->ignorepkg = alpm_list_add(handle->ignorepkg,
> strdup(pkg)); @@ -458,6 +492,13 @@ void
> alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs) if(ignorepkgs)
> handle->ignorepkg = ignorepkgs; }
>  
> +void SYMEXPORT alpm_option_remove_ignorepkg(const char *pkg)
> +{
> +	void *vdata;
> +	handle->ignorepkg = alpm_list_remove(handle->ignorepkg,
> strdup(pkg), 
> +		_alpm_str_cmp, &vdata);
> +}
> +
>  void SYMEXPORT alpm_option_add_holdpkg(const char *pkg)
>  {
>  	handle->holdpkg = alpm_list_add(handle->holdpkg,
> strdup(pkg)); @@ -469,6 +510,13 @@ void SYMEXPORT
> alpm_option_set_holdpkgs(alpm_list_t *holdpkgs) if(holdpkgs)
> handle->holdpkg = holdpkgs; }
>  
> +void SYMEXPORT alpm_option_remove_holdpkg(const char *pkg)
> +{
> +	void *vdata;
> +	handle->holdpkg = alpm_list_remove(handle->holdpkg,
> strdup(pkg), 
> +		_alpm_str_cmp, &vdata);
> +}
> +
>  void SYMEXPORT alpm_option_add_ignoregrp(const char *grp)
>  {
>  	handle->ignoregrp = alpm_list_add(handle->ignoregrp,
> strdup(grp)); @@ -480,6 +528,13 @@ void
> alpm_option_set_ignoregrps(alpm_list_t *ignoregrps) if(ignoregrps)
> handle->ignoregrp = ignoregrps; }
>  
> +void SYMEXPORT alpm_option_remove_ignoregrp(const char *grp)
> +{
> +	void *vdata;
> +	handle->ignoregrp = alpm_list_remove(handle->ignoregrp,
> strdup(grp), 
> +		_alpm_str_cmp, &vdata);
> +}
> +
>  void SYMEXPORT alpm_option_set_upgradedelay(time_t delay)
>  {
>  	handle->upgradedelay = delay;

Hmm. This patch seems useful, however it introduces some memleaks
(the "result" of alpm_list_remove in vdata should be freed, and we
don't need strdup(pkg) here). After fixing these, this patch can be
applied imho.

Bye




More information about the pacman-dev mailing list