From a5d8d486ea6e254eb1c1aa138a01f9261906217e Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 27 Apr 2010 18:02:15 +0200 Subject: [PATCH] xbps-repo: show a warning when a repository has been already added. --HG-- extra : convert_revision : xtraeme%40gmail.com-20100427160215-pi2urhu9xzeblv71 --- bin/xbps-repo/defs.h | 4 +-- bin/xbps-repo/repository.c | 68 +++++++++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/bin/xbps-repo/defs.h b/bin/xbps-repo/defs.h index 70e61480..330ebcd0 100644 --- a/bin/xbps-repo/defs.h +++ b/bin/xbps-repo/defs.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009 Juan Romero Pardines. + * Copyright (c) 2009-2010 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,8 +29,6 @@ /* From index.c */ int xbps_repo_genindex(const char *); /* From repository.c */ -int pkgindex_verify(const char *, const char *, bool); -bool sanitize_url(char *, const char *); int register_repository(const char *); int unregister_repository(const char *); int show_pkg_info_from_repolist(const char *); diff --git a/bin/xbps-repo/repository.c b/bin/xbps-repo/repository.c index bb42d2c0..526fc939 100644 --- a/bin/xbps-repo/repository.c +++ b/bin/xbps-repo/repository.c @@ -34,12 +34,16 @@ #include #include "defs.h" -int -pkgindex_verify(const char *plist, const char *uri, bool only_sync) +struct repoinfo { + char *pkgidxver; + uint64_t totalpkgs; +}; + +static struct repoinfo * +pkgindex_verify(const char *plist, const char *uri) { + struct repoinfo *rpi = NULL; prop_dictionary_t d; - const char *pkgidx_version; - uint64_t total_pkgs; int rv = 0; assert(plist != NULL); @@ -49,45 +53,52 @@ pkgindex_verify(const char *plist, const char *uri, bool only_sync) fprintf(stderr, "E: repository %s does not contain any " "xbps pkgindex file.\n", uri); - return errno; + return NULL; } - if (!prop_dictionary_get_cstring_nocopy(d, - "pkgindex-version", &pkgidx_version)) { + if ((rpi = malloc(sizeof(*rpi))) == NULL) { + rv = errno; + goto out; + } + + if (!prop_dictionary_get_cstring(d, + "pkgindex-version", &rpi->pkgidxver)) { fprintf(stderr, "E: missing 'pkgindex-version' object!\n"); rv = errno; goto out; } - if (!prop_dictionary_get_uint64(d, "total-pkgs", &total_pkgs)) { + if (!prop_dictionary_get_uint64(d, "total-pkgs", + &rpi->totalpkgs)) { fprintf(stderr, "E: missing 'total-pkgs' object!\n"); rv = errno; goto out; } /* Reject empty repositories, how could this happen? :-) */ - if (total_pkgs == 0) { + if (rpi->totalpkgs == 0) { fprintf(stderr, "E: empty package list!\n"); rv = EINVAL; goto out; } - printf("%s package index at %s (v%s) with %ju packages.\n", - only_sync ? "Updated" : "Added", uri, pkgidx_version, total_pkgs); - out: prop_object_release(d); if (rv != 0) { fprintf(stderr, "W: removing incorrect pkg index file: '%s' ...\n", plist); - rv = remove(plist); + (void)remove(plist); + if (rpi) { + free(rpi); + rpi = NULL; + } } - return rv; + return rpi; } -bool +static bool sanitize_url(char *buf, const char *path) { char *dirnp, *basenp, *dir, *base, *tmp; @@ -152,6 +163,7 @@ unregister_repository(const char *uri) int register_repository(const char *uri) { + struct repoinfo *rpi = NULL; char *metadir, *plist, idxstr[PATH_MAX]; int rv = 0; @@ -199,16 +211,26 @@ register_repository(const char *uri) if (plist == NULL) return errno; - if ((rv = pkgindex_verify(plist, idxstr, false)) != 0) + if ((rpi = pkgindex_verify(plist, uri)) == NULL) goto out; - if ((rv = xbps_repository_register(idxstr)) != 0) { + rv = xbps_repository_register(idxstr); + if (rv != 0 && rv != EEXIST) { fprintf(stderr, "E: couldn't register repository (%s)\n", strerror(rv)); goto out; + } else if (rv == EEXIST) { + fprintf(stderr, "W: repository already registered.\n"); + rv = 0; + goto out; } - + + printf("Added package index at %s (v%s) with %ju packages.\n", + uri, rpi->pkgidxver, rpi->totalpkgs); + out: + if (rpi != NULL) + free(rpi); if (plist != NULL) free(plist); @@ -295,6 +317,8 @@ repository_sync(void) int rv = 0; SIMPLEQ_FOREACH(rp, &rp_queue, rp_entries) { + struct repoinfo *rpi = NULL; + if (!xbps_check_is_repo_string_remote(rp->rp_uri)) continue; @@ -312,7 +336,13 @@ repository_sync(void) rv = EINVAL; break; } - (void)pkgindex_verify(plist, rp->rp_uri, true); + if ((rpi = pkgindex_verify(plist, rp->rp_uri)) == NULL) { + rv = errno; + break; + } + printf("Updated package index at %s (v%s) with %ju packages.\n", + rp->rp_uri, rpi->pkgidxver, rpi->totalpkgs); + free(rpi); free(plist); }