[pacman-dev] [PATCH] Skip special files when cleaning package cache

Dave Reisner d at falconindy.com
Fri Mar 9 09:12:25 EST 2012


On Fri, Mar 09, 2012 at 03:08:37PM +0100, Lukas Fleischer wrote:
> On Fri, Mar 09, 2012 at 11:20:03PM +1000, Allan McRae wrote:
> > Ignore .sig, *.db*, and *.src.tar* when cleaning the package cache.
> > 
> > Fixes FS#25166.
> > 
> > Signed-off-by: Allan McRae <allan at archlinux.org>
> > ---
> > 
> > I am bad at regex...  so I am sure some of these could be tightened up.
> 
> Why use regular expressions at all? "*foo*"-style patterns can be easily
> matched using strstr(), "foo$" might require some more work but I'm
> pretty sure it can be implemented as a str*() one-liner as well (e.g.
> using strlen() and strcmp()).

I think you mean fnmatch here, and I agree.

> > 
> >  src/pacman/sync.c |   22 ++++++++++++++++++++++
> >  1 file changed, 22 insertions(+)
> > 
> > diff --git a/src/pacman/sync.c b/src/pacman/sync.c
> > index e69ca58..c617e0b 100644
> > --- a/src/pacman/sync.c
> > +++ b/src/pacman/sync.c
> > @@ -26,6 +26,7 @@
> >  #include <errno.h>
> >  #include <dirent.h>
> >  #include <sys/stat.h>
> > +#include <regex.h>
> >  
> >  #include <alpm.h>
> >  #include <alpm_list.h>
> > @@ -170,6 +171,7 @@ static int sync_cleancache(int level)
> >  	alpm_db_t *db_local = alpm_get_localdb(config->handle);
> >  	alpm_list_t *cachedirs = alpm_option_get_cachedirs(config->handle);
> >  	int ret = 0;
> > +	regex_t sigreg, dbreg, srcpkgreg;
> >  
> >  	for(i = cachedirs; i; i = alpm_list_next(i)) {
> >  		printf(_("Cache directory: %s\n"), (const char *)i->data);
> > @@ -199,6 +201,10 @@ static int sync_cleancache(int level)
> >  		printf(_("removing all files from cache...\n"));
> >  	}
> >  
> > +	regcomp(&sigreg, "\\.sig$", REG_EXTENDED | REG_NEWLINE);
> > +	regcomp(&dbreg, "\\.db(\\.tar[^[:space:]]*)?$", REG_EXTENDED | REG_NEWLINE);
> > +	regcomp(&srcpkgreg, "\\.src\\.tar", REG_EXTENDED | REG_NEWLINE);
> > +
> >  	for(i = cachedirs; i; i = alpm_list_next(i)) {
> >  		const char *cachedir = i->data;
> >  		DIR *dir = opendir(cachedir);
> > @@ -222,6 +228,22 @@ static int sync_cleancache(int level)
> >  			if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
> >  				continue;
> >  			}
> > +
> > +			/* skip signature files - they are removed with their package file */
> > +			if(regexec(&sigreg, ent->d_name, 0, 0, 0) == 0) {
> > +				continue;
> > +			}
> > +
> > +			/* skip package database within the cache directory */
> > +			if(regexec(&dbreg, ent->d_name, 0, 0, 0) == 0) {
> > +				continue;
> > +			}
> > +
> > +			/* skip source packages withing the cache directory */
> > +			if(regexec(&srcpkgreg, ent->d_name, 0, 0, 0) == 0) {
> > +				continue;
> > +			}
> > +
> >  			/* build the full filepath */
> >  			snprintf(path, PATH_MAX, "%s%s", cachedir, ent->d_name);
> >  
> > -- 
> > 1.7.9.3
> 


More information about the pacman-dev mailing list