xbps-rindex: -a does not remove outdated binpkgs anymore; use -r instead.

This commit is contained in:
Juan RP 2012-12-15 11:13:32 +01:00
parent b75cd05c37
commit bb877b0db7
7 changed files with 47 additions and 108 deletions

4
NEWS
View File

@ -1,5 +1,9 @@
xbps-0.19 (???): 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 * xbps-rindex(8): clean (-c) and remove obsoletes mode (-r) are
now multithreaded and will spawn a thread per core to speed up now multithreaded and will spawn a thread per core to speed up
the process considerably. the process considerably.

View File

@ -2,7 +2,7 @@ TOPDIR = ../..
-include $(TOPDIR)/config.mk -include $(TOPDIR)/config.mk
BIN = xbps-rindex 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 MAN = $(BIN).8
include $(TOPDIR)/mk/prog.mk include $(TOPDIR)/mk/prog.mk

View File

@ -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 <sys/stat.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
#include <libgen.h>
#include <assert.h>
#include <xbps_api.h>
#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;
}

View File

@ -28,9 +28,6 @@
#include <xbps_api.h> #include <xbps_api.h>
/* From common.c */
int remove_pkg(const char *, const char *, const char *);
/* From index-add.c */ /* From index-add.c */
int index_add(struct xbps_handle *, int, char **); int index_add(struct xbps_handle *, int, char **);

View File

@ -50,10 +50,10 @@ index_add(struct xbps_handle *xhp, int argc, char **argv)
struct stat st; struct stat st;
const char *pkgname, *version, *regver, *oldfilen, *oldpkgver; const char *pkgname, *version, *regver, *oldfilen, *oldpkgver;
const char *pkgver, *arch, *oldarch; const char *pkgver, *arch, *oldarch;
char *sha256, *filen, *repodir, *buf, *buf2; char *sha256, *filen, *repodir, *buf;
char *tmpfilen, *tmprepodir, *plist, *plistf; char *tmpfilen, *tmprepodir, *plist, *plistf;
size_t x; size_t x;
int i, ret = 0, rv = 0; int i, ret = 0;
bool files_flush = false, found = false, flush = false; bool files_flush = false, found = false, flush = false;
idx = idxfiles = newpkgd = newpkgfilesd = curpkgd = NULL; 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, prop_dictionary_get_cstring_nocopy(curpkgd,
"version", &regver); "version", &regver);
ret = xbps_cmpver(version, regver); ret = xbps_cmpver(version, regver);
if (ret == 0) { if (ret <= 0) {
/* Same version */ /* Same version or index version greater */
fprintf(stderr, "index: skipping `%s-%s' " fprintf(stderr, "index: skipping `%s-%s' "
"(%s), already registered.\n", "(%s), already registered.\n",
pkgname, version, arch); pkgname, version, arch);
prop_object_release(newpkgd); prop_object_release(newpkgd);
free(tmpfilen); free(tmpfilen);
continue; 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 * Current package version is greater than
* index version. * index version.
*/ */
buf = xbps_xasprintf("`%s' (%s)", oldpkgver, oldarch); 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); prop_dictionary_remove(idx, pkgname);
free(buf2); printf("index: removed obsolete entry %s.\n", buf);
printf("index: removed obsolete entry/binpkg %s.\n", buf);
free(buf); free(buf);
} }
/* /*

View File

@ -46,6 +46,39 @@ struct thread_data {
int thread_num; 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 * static void *
cleaner_thread(void *arg) cleaner_thread(void *arg)
{ {

View File

@ -1,4 +1,4 @@
.Dd November 6, 2012 .Dd December 15, 2012
.Os Void Linux .Os Void Linux
.Dt xbps-rindex 8 .Dt xbps-rindex 8
.Sh NAME .Sh NAME
@ -24,16 +24,15 @@ Show the XBPS version.
.Pp .Pp
.Bl -tag -width x .Bl -tag -width x
.It Sy -a, --add Ar /path/to/repo/binpkg.xbps ... .It Sy -a, --add Ar /path/to/repo/binpkg.xbps ...
Registers the binary package into the local repository and if an older Registers the binary package into the local repository, replacing
binary package exists, it's removed and new entry is added to the index. existing version. Multiple binary packages can be specified as arguments.
Multiple binary packages can be specified as arguments.
.It Sy -c, --clean Ar repository .It Sy -c, --clean Ar repository
Removes obsolete entries found in the local repository's index. Removes obsolete entries found in the local repository's index.
.It Sy -r, --remove-obsoletes Ar repository .It Sy -r, --remove-obsoletes Ar repository
Removes obsolete packages from Removes obsolete packages from
.Ar repository . .Ar repository .
Packages that are not currently registered in repository's index will Packages that are not currently registered in repository's index will
be removed. be removed (out of date, invalid archives, etc).
.Sh SEE ALSO .Sh SEE ALSO
.Xr xbps-create 8 , .Xr xbps-create 8 ,
.Xr xbps-dgraph 8 , .Xr xbps-dgraph 8 ,