Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=0a0a1e4ce5410516dd270e4c1639d1d74f218199

commit 0a0a1e4ce5410516dd270e4c1639d1d74f218199
Author: Michel Hermier <[email protected]>
Date:   Mon Dec 9 23:18:23 2013 +0100

libpacman: Move _pacman_sync_cleancache to package/packagecache.*.

diff --git a/lib/libpacman/CMakeLists.txt b/lib/libpacman/CMakeLists.txt
index cf461d5..aa32505 100644
--- a/lib/libpacman/CMakeLists.txt
+++ b/lib/libpacman/CMakeLists.txt
@@ -25,6 +25,7 @@ set(LIBPACMAN_SOURCES
db/localdb.c
db/localdb_files.c
db/syncdb.c
+       package/packagecache.c
package/pkginfo.c
add.c
be_files.c
diff --git a/lib/libpacman/cache.c b/lib/libpacman/cache.c
index 2b4fcd9..cece58a 100644
--- a/lib/libpacman/cache.c
+++ b/lib/libpacman/cache.c
@@ -271,92 +271,4 @@ pmgrp_t *_pacman_db_get_grpfromcache(pmdb_t *db, const 
char *target)
return(NULL);
}

-int _pacman_sync_cleancache(int level)
-{
-       char dirpath[PATH_MAX];
-
-       snprintf(dirpath, PATH_MAX, "%s%s", handle->root, handle->cachedir);
-
-       if(!level) {
-               /* incomplete cleanup: we keep latest packages and partial 
downloads */
-               DIR *dir;
-               struct dirent *ent;
-               pmlist_t *cache = NULL;
-               pmlist_t *clean = NULL;
-               pmlist_t *i, *j;
-
-               dir = opendir(dirpath);
-               if(dir == NULL) {
-                       RET_ERR(PM_ERR_NO_CACHE_ACCESS, -1);
-               }
-               rewinddir(dir);
-               while((ent = readdir(dir)) != NULL) {
-                       if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, 
"..")) {
-                               continue;
-                       }
-                       cache = _pacman_stringlist_append(cache, ent->d_name);
-               }
-               closedir(dir);
-
-               for(i = cache; i; i = i->next) {
-                       char *str = i->data;
-                       char name[PKG_NAME_LEN], version[PKG_VERSION_LEN];
-
-                       if(strstr(str, PM_EXT_PKG) == NULL) {
-                               clean = _pacman_stringlist_append(clean, str);
-                               continue;
-                       }
-                       /* we keep partially downloaded files */
-                       if(strstr(str, PM_EXT_PKG ".part")) {
-                               continue;
-                       }
-                       if(_pacman_pkg_splitname(str, name, version, 1) != 0) {
-                               clean = _pacman_stringlist_append(clean, str);
-                               continue;
-                       }
-                       for(j = i->next; j; j = j->next) {
-                               char *s = j->data;
-                               char n[PKG_NAME_LEN], v[PKG_VERSION_LEN];
-
-                               if(strstr(s, PM_EXT_PKG) == NULL) {
-                                       continue;
-                               }
-                               if(strstr(s, PM_EXT_PKG ".part")) {
-                                       continue;
-                               }
-                               if(_pacman_pkg_splitname(s, n, v, 1) != 0) {
-                                       continue;
-                               }
-                               if(!strcmp(name, n)) {
-                                       char *ptr = (pacman_pkg_vercmp(version, 
v) < 0) ? str : s;
-                                       if(!_pacman_list_is_strin(ptr, clean)) {
-                                               clean = 
_pacman_stringlist_append(clean, ptr);
-                                       }
-                               }
-                       }
-               }
-               FREELIST(cache);
-
-               for(i = clean; i; i = i->next) {
-                       char path[PATH_MAX];
-
-                       snprintf(path, PATH_MAX, "%s/%s", dirpath, (char 
*)i->data);
-                       unlink(path);
-               }
-               FREELIST(clean);
-       } else {
-               /* full cleanup */
-
-               if(_pacman_rmrf(dirpath)) {
-                       RET_ERR(PM_ERR_CANT_REMOVE_CACHE, -1);
-               }
-
-               if(_pacman_makepath(dirpath)) {
-                       RET_ERR(PM_ERR_CANT_CREATE_CACHE, -1);
-               }
-       }
-
-       return(0);
-}
-
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/cache.h b/lib/libpacman/cache.h
index f125ba6..82d2c20 100644
--- a/lib/libpacman/cache.h
+++ b/lib/libpacman/cache.h
@@ -36,7 +36,6 @@ pmlist_t *_pacman_db_whatprovides(pmdb_t *db, char *package);
/* groups */
pmlist_t *_pacman_db_get_grpcache(pmdb_t *db);
pmgrp_t *_pacman_db_get_grpfromcache(pmdb_t *db, const char *target);
-int _pacman_sync_cleancache(int level);

#endif /* _PACMAN_CACHE_H */

diff --git a/lib/libpacman/package/packagecache.c 
b/lib/libpacman/package/packagecache.c
new file mode 100644
index 0000000..1250bc9
--- /dev/null
+++ b/lib/libpacman/package/packagecache.c
@@ -0,0 +1,122 @@
+/*
+ *  package/packagecache.c
+ *
+ *  Copyright (c) 2002-2006 by Judd Vinet <[email protected]>
+ *  Copyright (c) 2007 by Miklos Vajna <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+
+#include "config.h"
+
+#include <dirent.h>
+
+/* pacman-g2 */
+#include "package/packagecache.h"
+
+#include "util/list.h"
+#include "package.h"
+#include "handle.h"
+
+int _pacman_sync_cleancache(int level)
+{
+       char dirpath[PATH_MAX];
+
+       snprintf(dirpath, PATH_MAX, "%s%s", handle->root, handle->cachedir);
+
+       if(!level) {
+               /* incomplete cleanup: we keep latest packages and partial 
downloads */
+               DIR *dir;
+               struct dirent *ent;
+               pmlist_t *cache = NULL;
+               pmlist_t *clean = NULL;
+               pmlist_t *i, *j;
+
+               dir = opendir(dirpath);
+               if(dir == NULL) {
+                       RET_ERR(PM_ERR_NO_CACHE_ACCESS, -1);
+               }
+               rewinddir(dir);
+               while((ent = readdir(dir)) != NULL) {
+                       if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, 
"..")) {
+                               continue;
+                       }
+                       cache = _pacman_stringlist_append(cache, ent->d_name);
+               }
+               closedir(dir);
+
+               for(i = cache; i; i = i->next) {
+                       char *str = i->data;
+                       char name[PKG_NAME_LEN], version[PKG_VERSION_LEN];
+
+                       if(strstr(str, PM_EXT_PKG) == NULL) {
+                               clean = _pacman_stringlist_append(clean, str);
+                               continue;
+                       }
+                       /* we keep partially downloaded files */
+                       if(strstr(str, PM_EXT_PKG ".part")) {
+                               continue;
+                       }
+                       if(_pacman_pkg_splitname(str, name, version, 1) != 0) {
+                               clean = _pacman_stringlist_append(clean, str);
+                               continue;
+                       }
+                       for(j = i->next; j; j = j->next) {
+                               char *s = j->data;
+                               char n[PKG_NAME_LEN], v[PKG_VERSION_LEN];
+
+                               if(strstr(s, PM_EXT_PKG) == NULL) {
+                                       continue;
+                               }
+                               if(strstr(s, PM_EXT_PKG ".part")) {
+                                       continue;
+                               }
+                               if(_pacman_pkg_splitname(s, n, v, 1) != 0) {
+                                       continue;
+                               }
+                               if(!strcmp(name, n)) {
+                                       char *ptr = (pacman_pkg_vercmp(version, 
v) < 0) ? str : s;
+                                       if(!_pacman_list_is_strin(ptr, clean)) {
+                                               clean = 
_pacman_stringlist_append(clean, ptr);
+                                       }
+                               }
+                       }
+               }
+               FREELIST(cache);
+
+               for(i = clean; i; i = i->next) {
+                       char path[PATH_MAX];
+
+                       snprintf(path, PATH_MAX, "%s/%s", dirpath, (char 
*)i->data);
+                       unlink(path);
+               }
+               FREELIST(clean);
+       } else {
+               /* full cleanup */
+
+               if(_pacman_rmrf(dirpath)) {
+                       RET_ERR(PM_ERR_CANT_REMOVE_CACHE, -1);
+               }
+
+               if(_pacman_makepath(dirpath)) {
+                       RET_ERR(PM_ERR_CANT_CREATE_CACHE, -1);
+               }
+       }
+
+       return(0);
+}
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/package/packagecache.h 
b/lib/libpacman/package/packagecache.h
new file mode 100644
index 0000000..dc4b3d3
--- /dev/null
+++ b/lib/libpacman/package/packagecache.h
@@ -0,0 +1,28 @@
+/*
+ *  package/packagecache.h
+ *
+ *  Copyright (c) 2002-2006 by Judd Vinet <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+#ifndef _PACMAN_PACKAGECACHE_H
+#define _PACMAN_PACKAGECACHE_H
+
+int _pacman_sync_cleancache(int level);
+
+#endif /* _PACMAN_PACKAGECACHE_H */
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/pacman.c b/lib/libpacman/pacman.c
index fcf325a..d8f4a45 100644
--- a/lib/libpacman/pacman.c
+++ b/lib/libpacman/pacman.c
@@ -43,6 +43,7 @@
#include "db/syncdb.h"
#include "hash/md5.h"
#include "hash/sha1.h"
+#include "package/packagecache.h"
#include "util/list.h"
#include "util/log.h"
#include "util/stringlist.h"
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to