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

Allan McRae allan at archlinux.org
Fri Mar 9 08:20:03 EST 2012


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.

 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