xbps-rindex: -a does not remove outdated binpkgs anymore; use -r instead.
This commit is contained in:
		
							
								
								
									
										4
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								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.
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
@@ -28,9 +28,6 @@
 | 
			
		||||
 | 
			
		||||
#include <xbps_api.h>
 | 
			
		||||
 | 
			
		||||
/* From common.c */
 | 
			
		||||
int	remove_pkg(const char *, const char *, const char *);
 | 
			
		||||
 | 
			
		||||
/* From index-add.c */
 | 
			
		||||
int	index_add(struct xbps_handle *, int, char **);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
		}
 | 
			
		||||
		/*
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -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 ,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user