xbps-repo: show a warning when a repository has been already added.
--HG-- extra : convert_revision : xtraeme%40gmail.com-20100427160215-pi2urhu9xzeblv71
This commit is contained in:
parent
b77bebe03a
commit
a5d8d486ea
@ -1,5 +1,5 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2009 Juan Romero Pardines.
|
* Copyright (c) 2009-2010 Juan Romero Pardines.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -29,8 +29,6 @@
|
|||||||
/* From index.c */
|
/* From index.c */
|
||||||
int xbps_repo_genindex(const char *);
|
int xbps_repo_genindex(const char *);
|
||||||
/* From repository.c */
|
/* From repository.c */
|
||||||
int pkgindex_verify(const char *, const char *, bool);
|
|
||||||
bool sanitize_url(char *, const char *);
|
|
||||||
int register_repository(const char *);
|
int register_repository(const char *);
|
||||||
int unregister_repository(const char *);
|
int unregister_repository(const char *);
|
||||||
int show_pkg_info_from_repolist(const char *);
|
int show_pkg_info_from_repolist(const char *);
|
||||||
|
@ -34,12 +34,16 @@
|
|||||||
#include <xbps_api.h>
|
#include <xbps_api.h>
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
int
|
struct repoinfo {
|
||||||
pkgindex_verify(const char *plist, const char *uri, bool only_sync)
|
char *pkgidxver;
|
||||||
|
uint64_t totalpkgs;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct repoinfo *
|
||||||
|
pkgindex_verify(const char *plist, const char *uri)
|
||||||
{
|
{
|
||||||
|
struct repoinfo *rpi = NULL;
|
||||||
prop_dictionary_t d;
|
prop_dictionary_t d;
|
||||||
const char *pkgidx_version;
|
|
||||||
uint64_t total_pkgs;
|
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(plist != NULL);
|
assert(plist != NULL);
|
||||||
@ -49,45 +53,52 @@ pkgindex_verify(const char *plist, const char *uri, bool only_sync)
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"E: repository %s does not contain any "
|
"E: repository %s does not contain any "
|
||||||
"xbps pkgindex file.\n", uri);
|
"xbps pkgindex file.\n", uri);
|
||||||
return errno;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!prop_dictionary_get_cstring_nocopy(d,
|
if ((rpi = malloc(sizeof(*rpi))) == NULL) {
|
||||||
"pkgindex-version", &pkgidx_version)) {
|
rv = errno;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!prop_dictionary_get_cstring(d,
|
||||||
|
"pkgindex-version", &rpi->pkgidxver)) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"E: missing 'pkgindex-version' object!\n");
|
"E: missing 'pkgindex-version' object!\n");
|
||||||
rv = errno;
|
rv = errno;
|
||||||
goto out;
|
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");
|
fprintf(stderr, "E: missing 'total-pkgs' object!\n");
|
||||||
rv = errno;
|
rv = errno;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reject empty repositories, how could this happen? :-) */
|
/* Reject empty repositories, how could this happen? :-) */
|
||||||
if (total_pkgs == 0) {
|
if (rpi->totalpkgs == 0) {
|
||||||
fprintf(stderr, "E: empty package list!\n");
|
fprintf(stderr, "E: empty package list!\n");
|
||||||
rv = EINVAL;
|
rv = EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s package index at %s (v%s) with %ju packages.\n",
|
|
||||||
only_sync ? "Updated" : "Added", uri, pkgidx_version, total_pkgs);
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
prop_object_release(d);
|
prop_object_release(d);
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"W: removing incorrect pkg index file: '%s' ...\n",
|
"W: removing incorrect pkg index file: '%s' ...\n",
|
||||||
plist);
|
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)
|
sanitize_url(char *buf, const char *path)
|
||||||
{
|
{
|
||||||
char *dirnp, *basenp, *dir, *base, *tmp;
|
char *dirnp, *basenp, *dir, *base, *tmp;
|
||||||
@ -152,6 +163,7 @@ unregister_repository(const char *uri)
|
|||||||
int
|
int
|
||||||
register_repository(const char *uri)
|
register_repository(const char *uri)
|
||||||
{
|
{
|
||||||
|
struct repoinfo *rpi = NULL;
|
||||||
char *metadir, *plist, idxstr[PATH_MAX];
|
char *metadir, *plist, idxstr[PATH_MAX];
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
@ -199,16 +211,26 @@ register_repository(const char *uri)
|
|||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
if ((rv = pkgindex_verify(plist, idxstr, false)) != 0)
|
if ((rpi = pkgindex_verify(plist, uri)) == NULL)
|
||||||
goto out;
|
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",
|
fprintf(stderr, "E: couldn't register repository (%s)\n",
|
||||||
strerror(rv));
|
strerror(rv));
|
||||||
goto out;
|
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:
|
out:
|
||||||
|
if (rpi != NULL)
|
||||||
|
free(rpi);
|
||||||
if (plist != NULL)
|
if (plist != NULL)
|
||||||
free(plist);
|
free(plist);
|
||||||
|
|
||||||
@ -295,6 +317,8 @@ repository_sync(void)
|
|||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
SIMPLEQ_FOREACH(rp, &rp_queue, rp_entries) {
|
SIMPLEQ_FOREACH(rp, &rp_queue, rp_entries) {
|
||||||
|
struct repoinfo *rpi = NULL;
|
||||||
|
|
||||||
if (!xbps_check_is_repo_string_remote(rp->rp_uri))
|
if (!xbps_check_is_repo_string_remote(rp->rp_uri))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -312,7 +336,13 @@ repository_sync(void)
|
|||||||
rv = EINVAL;
|
rv = EINVAL;
|
||||||
break;
|
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);
|
free(plist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user