FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 03-09-2012, 12:20 PM
Allan McRae
 
Default Skip special files when cleaning package cache

Ignore .sig, *.db*, and *.src.tar* when cleaning the package cache.

Fixes FS#25166.

Signed-off-by: Allan McRae <allan@archlinux.org>
---

I am bad at regex... so I am sure some of these could be tightened up.

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
"), (const char *)i->data);
@@ -199,6 +201,10 @@ static int sync_cleancache(int level)
printf(_("removing all files from cache...
"));
}

+ 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
 
Old 03-09-2012, 01:08 PM
Lukas Fleischer
 
Default Skip special files when cleaning package cache

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@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()).

>
> 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
"), (const char *)i->data);
> @@ -199,6 +201,10 @@ static int sync_cleancache(int level)
> printf(_("removing all files from cache...
"));
> }
>
> + 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
 
Old 03-09-2012, 01:12 PM
Dave Reisner
 
Default Skip special files when cleaning package cache

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@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
"), (const char *)i->data);
> > @@ -199,6 +201,10 @@ static int sync_cleancache(int level)
> > printf(_("removing all files from cache...
"));
> > }
> >
> > + 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
>
 

Thread Tools




All times are GMT. The time now is 09:28 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org