Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Chantry <shiningxc@gmail.com>2009-09-18 21:59:52 +0200
committerDan McGee <dan@archlinux.org>2010-03-14 18:34:42 -0500
commit087be2f1fbae2d7168732c7004d8963a3d9d21d8 (patch)
tree2eab3707af6a0ec023bd45ecacff58c548bf5362
parent6f0ffb23860e8d1b4593d60e970919ae7b31340d (diff)
delta : add external cleanup script
Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--lib/libalpm/alpm.h1
-rw-r--r--lib/libalpm/delta.c46
-rw-r--r--src/util/.gitignore3
-rw-r--r--src/util/Makefile.am6
-rw-r--r--src/util/cleanupdelta.c134
5 files changed, 186 insertions, 4 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 05ad82eb..b0805068 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -234,6 +234,7 @@ int alpm_pkg_has_scriptlet(pmpkg_t *pkg);
int alpm_pkg_has_force(pmpkg_t *pkg);
off_t alpm_pkg_download_size(pmpkg_t *newpkg);
+alpm_list_t *alpm_pkg_unused_deltas(pmpkg_t *pkg);
/*
* Deltas
diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
index 523968ec..0fc37d97 100644
--- a/lib/libalpm/delta.c
+++ b/lib/libalpm/delta.c
@@ -71,7 +71,7 @@ off_t SYMEXPORT alpm_delta_get_size(pmdelta_t *delta)
/** @} */
-static alpm_list_t *graph_init(alpm_list_t *deltas)
+static alpm_list_t *graph_init(alpm_list_t *deltas, int reverse)
{
alpm_list_t *i, *j;
alpm_list_t *vertices = NULL;
@@ -101,7 +101,8 @@ static alpm_list_t *graph_init(alpm_list_t *deltas)
* 3_to_4
* If J 'from' is equal to I 'to', then J is a child of I.
* */
- if(strcmp(d_j->from, d_i->to) == 0) {
+ if((!reverse && strcmp(d_j->from, d_i->to) == 0) ||
+ (reverse && strcmp(d_j->to, d_i->from) == 0)) {
v_i->children = alpm_list_add(v_i->children, v_j);
}
}
@@ -233,7 +234,7 @@ off_t _alpm_shortest_delta_path(alpm_list_t *deltas,
_alpm_log(PM_LOG_DEBUG, "started delta shortest-path search for '%s'\n", to);
- vertices = graph_init(deltas);
+ vertices = graph_init(deltas, 0);
graph_init_size(vertices);
dijkstra(vertices);
bestsize = shortest_path(vertices, to, &bestpath);
@@ -247,6 +248,45 @@ off_t _alpm_shortest_delta_path(alpm_list_t *deltas,
return(bestsize);
}
+static alpm_list_t *find_unused(alpm_list_t *deltas, const char *to, off_t quota)
+{
+ alpm_list_t *unused = NULL;
+ alpm_list_t *vertices;
+ alpm_list_t *i;
+ vertices = graph_init(deltas, 1);
+
+ for(i = vertices; i; i = i->next) {
+ pmgraph_t *v = i->data;
+ pmdelta_t *vdelta = v->data;
+ if(strcmp(vdelta->to, to) == 0)
+ {
+ v->weight = vdelta->download_size;
+ }
+ }
+ dijkstra(vertices);
+ for(i = vertices; i; i = i->next) {
+ pmgraph_t *v = i->data;
+ pmdelta_t *vdelta = v->data;
+ if(v->weight > quota) {
+ unused = alpm_list_add(unused, vdelta->delta);
+ }
+ }
+ alpm_list_free_inner(vertices, _alpm_graph_free);
+ alpm_list_free(vertices);
+ return(unused);
+}
+
+alpm_list_t SYMEXPORT *alpm_pkg_unused_deltas(pmpkg_t *pkg)
+{
+ off_t pkgsize = alpm_pkg_get_size(pkg);
+ alpm_list_t *unused = find_unused(
+ alpm_pkg_get_deltas(pkg),
+ alpm_pkg_get_filename(pkg),
+ pkgsize * MAX_DELTA_RATIO);
+ return(unused);
+}
+
+
/** Parses the string representation of a pmdelta_t object.
* This function assumes that the string is in the correct format.
* This format is as follows:
diff --git a/src/util/.gitignore b/src/util/.gitignore
index c85ea2ca..9c855dff 100644
--- a/src/util/.gitignore
+++ b/src/util/.gitignore
@@ -6,3 +6,6 @@ testpkg
testpkg.exe
testdb
testdb.exe
+cleanupdelta
+cleanupdelta.exe
+
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 97a0ffa1..638e2764 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -3,7 +3,7 @@ conffile = ${sysconfdir}/pacman.conf
dbpath = ${localstatedir}/lib/pacman/
cachedir = ${localstatedir}/cache/pacman/pkg/
-bin_PROGRAMS = vercmp testpkg testdb
+bin_PROGRAMS = vercmp testpkg testdb cleanupdelta
DEFS = -DLOCALEDIR=\"@localedir@\" \
-DCONFFILE=\"$(conffile)\" \
@@ -24,4 +24,8 @@ testpkg_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
testdb_SOURCES = testdb.c
testdb_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
+cleanupdelta_SOURCES = cleanupdelta.c
+cleanupdelta_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
+
+
# vim:set ts=2 sw=2 noet:
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c
new file mode 100644
index 00000000..4b9ddd79
--- /dev/null
+++ b/src/util/cleanupdelta.c
@@ -0,0 +1,134 @@
+/*
+ * cleanupdelta.c : return list of unused delta in a given sync database
+ *
+ * Copyright (c) 2009 Pacman Development Team <pacman-dev@archlinux.org>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h> /* PATH_MAX */
+
+#include <alpm.h>
+#include <alpm_list.h>
+
+#define BASENAME "cleanupdelta"
+
+static void cleanup(int signum) {
+ if(alpm_release() == -1) {
+ fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
+ }
+
+ exit(signum);
+}
+
+void output_cb(pmloglevel_t level, char *fmt, va_list args)
+{
+ if(strlen(fmt)) {
+ switch(level) {
+ case PM_LOG_ERROR: printf("error: "); break;
+ case PM_LOG_WARNING: printf("warning: "); break;
+ //case PM_LOG_DEBUG: printf("debug: "); break;
+ default: return;
+ }
+ vprintf(fmt, args);
+ }
+}
+
+
+void checkpkgs(alpm_list_t *pkglist)
+{
+ alpm_list_t *i, *j;
+ for(i = pkglist; i; i = alpm_list_next(i)) {
+ pmpkg_t *pkg = alpm_list_getdata(i);
+ alpm_list_t *unused = alpm_pkg_unused_deltas(pkg);
+ for(j = unused; j; j = alpm_list_next(j)) {
+ char *delta = alpm_list_getdata(j);
+ printf("%s\n", delta);
+ }
+ alpm_list_free(unused);
+ }
+}
+
+void checkdbs(char *dbpath, alpm_list_t *dbnames) {
+ char syncdbpath[PATH_MAX];
+ pmdb_t *db = NULL;
+ alpm_list_t *i;
+
+ for(i = dbnames; i; i = alpm_list_next(i)) {
+ char *dbname = alpm_list_getdata(i);
+ snprintf(syncdbpath, PATH_MAX, "%s/sync/%s", dbpath, dbname);
+ db = alpm_db_register_sync(dbname);
+ if(db == NULL) {
+ fprintf(stderr, "error: could not register sync database (%s)\n",
+ alpm_strerrorlast());
+ return;
+ }
+ checkpkgs(alpm_db_get_pkgcache(db));
+ }
+
+}
+
+void usage() {
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr,
+ "\t%s [-b <pacman db>] core extra ... : check the listed sync databases\n", BASENAME);
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ char *dbpath = DBPATH;
+ int a = 1;
+ alpm_list_t *dbnames = NULL;
+
+ while(a < argc) {
+ if(strcmp(argv[a], "-b") == 0) {
+ if(++a < argc) {
+ dbpath = argv[a];
+ } else {
+ usage();
+ }
+ } else if(strcmp(argv[a], "-h") == 0 ||
+ strcmp(argv[a], "--help") == 0 ) {
+ usage();
+ } else {
+ dbnames = alpm_list_add(dbnames, argv[a]);
+ }
+ a++;
+ }
+
+ if(!dbnames) {
+ usage();
+ }
+
+ if(alpm_initialize() == -1) {
+ fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
+ return(1);
+ }
+
+ /* let us get log messages from libalpm */
+ alpm_option_set_logcb(output_cb);
+
+ alpm_option_set_dbpath(dbpath);
+
+ checkdbs(dbpath,dbnames);
+ alpm_list_free(dbnames);
+
+ cleanup(0);
+}
+
+/* vim: set ts=2 sw=2 noet: */