From bb877b0db7f36f746aa7c1c66abd9417f336b392 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 15 Dec 2012 11:13:32 +0100 Subject: [PATCH] xbps-rindex: -a does not remove outdated binpkgs anymore; use -r instead. --- NEWS | 4 ++ bin/xbps-rindex/Makefile | 2 +- bin/xbps-rindex/common.c | 70 ------------------------------ bin/xbps-rindex/defs.h | 3 -- bin/xbps-rindex/index-add.c | 34 +++------------ bin/xbps-rindex/remove-obsoletes.c | 33 ++++++++++++++ bin/xbps-rindex/xbps-rindex.8 | 9 ++-- 7 files changed, 47 insertions(+), 108 deletions(-) delete mode 100644 bin/xbps-rindex/common.c diff --git a/NEWS b/NEWS index cd9d1ba1..1a523103 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ xbps-0.19 (???): + * xbps-rindex(8): add mode (-a) does not remove old binary packages + in repository anymore, only its entry in index is replaced. To remove + outdated packages use -r/--remove-obsoletes. + * xbps-rindex(8): clean (-c) and remove obsoletes mode (-r) are now multithreaded and will spawn a thread per core to speed up the process considerably. diff --git a/bin/xbps-rindex/Makefile b/bin/xbps-rindex/Makefile index f41a4692..b5b17148 100644 --- a/bin/xbps-rindex/Makefile +++ b/bin/xbps-rindex/Makefile @@ -2,7 +2,7 @@ TOPDIR = ../.. -include $(TOPDIR)/config.mk BIN = xbps-rindex -OBJS = main.o index-add.o index-clean.o remove-obsoletes.o common.o +OBJS = main.o index-add.o index-clean.o remove-obsoletes.o MAN = $(BIN).8 include $(TOPDIR)/mk/prog.mk diff --git a/bin/xbps-rindex/common.c b/bin/xbps-rindex/common.c deleted file mode 100644 index a18c0207..00000000 --- a/bin/xbps-rindex/common.c +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * Copyright (c) 2012 Juan Romero Pardines. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "defs.h" - -int -remove_pkg(const char *repodir, const char *arch, const char *file) -{ - char *filepath; - int rv; - - filepath = xbps_xasprintf("%s/%s/%s", repodir, arch, file); - if (remove(filepath) == -1) { - if (errno != ENOENT) { - rv = errno; - xbps_error_printf("failed to remove old binpkg " - "`%s': %s\n", file, strerror(rv)); - free(filepath); - return rv; - } - } - free(filepath); - - filepath = xbps_xasprintf("%s/%s", repodir, file); - if (remove(filepath) == -1) { - if (errno != ENOENT) { - rv = errno; - xbps_error_printf("failed to remove old binpkg " - "`%s': %s\n", file, strerror(rv)); - free(filepath); - return rv; - } - } - free(filepath); - - return 0; -} diff --git a/bin/xbps-rindex/defs.h b/bin/xbps-rindex/defs.h index ad09e8a9..f2b2d940 100644 --- a/bin/xbps-rindex/defs.h +++ b/bin/xbps-rindex/defs.h @@ -28,9 +28,6 @@ #include -/* From common.c */ -int remove_pkg(const char *, const char *, const char *); - /* From index-add.c */ int index_add(struct xbps_handle *, int, char **); diff --git a/bin/xbps-rindex/index-add.c b/bin/xbps-rindex/index-add.c index 2ae172be..ac1aa6c2 100644 --- a/bin/xbps-rindex/index-add.c +++ b/bin/xbps-rindex/index-add.c @@ -50,10 +50,10 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) struct stat st; const char *pkgname, *version, *regver, *oldfilen, *oldpkgver; const char *pkgver, *arch, *oldarch; - char *sha256, *filen, *repodir, *buf, *buf2; + char *sha256, *filen, *repodir, *buf; char *tmpfilen, *tmprepodir, *plist, *plistf; size_t x; - int i, ret = 0, rv = 0; + int i, ret = 0; bool files_flush = false, found = false, flush = false; idx = idxfiles = newpkgd = newpkgfilesd = curpkgd = NULL; @@ -145,46 +145,22 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) prop_dictionary_get_cstring_nocopy(curpkgd, "version", ®ver); ret = xbps_cmpver(version, regver); - if (ret == 0) { - /* Same version */ + if (ret <= 0) { + /* Same version or index version greater */ fprintf(stderr, "index: skipping `%s-%s' " "(%s), already registered.\n", pkgname, version, arch); prop_object_release(newpkgd); free(tmpfilen); continue; - } else if (ret == -1) { - /* - * Index version is greater, remove current - * package. - */ - buf = xbps_xasprintf("`%s' (%s)", - oldpkgver, oldarch); - rv = remove_pkg(repodir, - oldarch, oldfilen); - if (rv != 0) - return rv; - - printf("index: removed obsolete binpkg %s.\n", buf); - free(buf); - prop_object_release(newpkgd); - free(tmpfilen); - continue; } /* * Current package version is greater than * index version. */ buf = xbps_xasprintf("`%s' (%s)", oldpkgver, oldarch); - buf2 = strdup(oldpkgver); - assert(buf2); - rv = remove_pkg(repodir, oldarch, oldfilen); - if (rv != 0) - return rv; - prop_dictionary_remove(idx, pkgname); - free(buf2); - printf("index: removed obsolete entry/binpkg %s.\n", buf); + printf("index: removed obsolete entry %s.\n", buf); free(buf); } /* diff --git a/bin/xbps-rindex/remove-obsoletes.c b/bin/xbps-rindex/remove-obsoletes.c index 9381b70e..96c0c983 100644 --- a/bin/xbps-rindex/remove-obsoletes.c +++ b/bin/xbps-rindex/remove-obsoletes.c @@ -46,6 +46,39 @@ struct thread_data { int thread_num; }; +static int +remove_pkg(const char *repodir, const char *arch, const char *file) +{ + char *filepath; + int rv; + + filepath = xbps_xasprintf("%s/%s/%s", repodir, arch, file); + if (remove(filepath) == -1) { + if (errno != ENOENT) { + rv = errno; + xbps_error_printf("failed to remove old binpkg " + "`%s': %s\n", file, strerror(rv)); + free(filepath); + return rv; + } + } + free(filepath); + + filepath = xbps_xasprintf("%s/%s", repodir, file); + if (remove(filepath) == -1) { + if (errno != ENOENT) { + rv = errno; + xbps_error_printf("failed to remove old binpkg " + "`%s': %s\n", file, strerror(rv)); + free(filepath); + return rv; + } + } + free(filepath); + + return 0; +} + static void * cleaner_thread(void *arg) { diff --git a/bin/xbps-rindex/xbps-rindex.8 b/bin/xbps-rindex/xbps-rindex.8 index 2684421b..71b5c2f4 100644 --- a/bin/xbps-rindex/xbps-rindex.8 +++ b/bin/xbps-rindex/xbps-rindex.8 @@ -1,4 +1,4 @@ -.Dd November 6, 2012 +.Dd December 15, 2012 .Os Void Linux .Dt xbps-rindex 8 .Sh NAME @@ -24,16 +24,15 @@ Show the XBPS version. .Pp .Bl -tag -width x .It Sy -a, --add Ar /path/to/repo/binpkg.xbps ... -Registers the binary package into the local repository and if an older -binary package exists, it's removed and new entry is added to the index. -Multiple binary packages can be specified as arguments. +Registers the binary package into the local repository, replacing +existing version. Multiple binary packages can be specified as arguments. .It Sy -c, --clean Ar repository Removes obsolete entries found in the local repository's index. .It Sy -r, --remove-obsoletes Ar repository Removes obsolete packages from .Ar repository . Packages that are not currently registered in repository's index will -be removed. +be removed (out of date, invalid archives, etc). .Sh SEE ALSO .Xr xbps-create 8 , .Xr xbps-dgraph 8 ,