From ca9d72d460516c5055fab17689ef076efdad99e0 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 18 Aug 2009 14:12:44 +0200 Subject: [PATCH] Implement blueprint 'xbps-repo-list-via-cmdline'. A new target (add-pkgidx) has been added to the xbps-repo command, that takes two args, local repository dir and path to binpkg. --HG-- extra : convert_revision : xtraeme%40gmail.com-20090818121244-pfdagkfqeukn1t2r --- bin/xbps-repo/index.c | 31 ++++++++++++++++++++++--------- bin/xbps-repo/index.h | 1 + bin/xbps-repo/main.c | 15 +++++++++++++-- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/bin/xbps-repo/index.c b/bin/xbps-repo/index.c index 3afa3b99..98d07a1e 100644 --- a/bin/xbps-repo/index.c +++ b/bin/xbps-repo/index.c @@ -74,8 +74,8 @@ out: return dict; } -static int -repoidx_addpkg(const char *file, const char *filename, const char *pkgdir) +int +xbps_repo_addpkg_index(const char *file, const char *pkgdir) { prop_dictionary_t newpkgd, idxdict, curpkgd; prop_array_t pkgar; @@ -83,9 +83,22 @@ repoidx_addpkg(const char *file, const char *filename, const char *pkgdir) struct archive_entry *entry; struct stat st; const char *pkgname, *version, *regver; - char *sha256, *plist; + char *sha256, *plist, *filen = NULL, *tmpfilen = NULL; int rv = 0; + assert(file != NULL); + assert(pkgdir != NULL); + + tmpfilen = strdup(file); + if (tmpfilen == NULL) + return errno; + + filen = basename(tmpfilen); + if (strcmp(tmpfilen, filen) == 0) { + free(tmpfilen); + return EINVAL; + } + ar = archive_read_new(); if (ar == NULL) { rv = errno; @@ -146,7 +159,7 @@ repoidx_addpkg(const char *file, const char *filename, const char *pkgdir) "version", ®ver); if (xbps_cmpver(version, regver) <= 0) { printf("Skipping %s. Version %s already " - "registered.\n", filename, regver); + "registered.\n", filen, regver); prop_object_release(newpkgd); archive_read_data_skip(ar); break; @@ -168,16 +181,14 @@ repoidx_addpkg(const char *file, const char *filename, const char *pkgdir) * We have the dictionary now, add the required * objects for the index. */ - prop_dictionary_set_cstring_nocopy(newpkgd, "filename", - filename); + prop_dictionary_set_cstring_nocopy(newpkgd, "filename", filen); sha256 = xbps_get_file_hash(file); if (sha256 == NULL) { prop_object_release(newpkgd); rv = errno; break; } - prop_dictionary_set_cstring(newpkgd, "filename-sha256", - sha256); + prop_dictionary_set_cstring(newpkgd, "filename-sha256", sha256); free(sha256); if (stat(file, &st) == -1) { @@ -219,6 +230,8 @@ out2: out1: archive_read_finish(ar); out: + free(tmpfilen); + return rv; } @@ -270,7 +283,7 @@ xbps_repo_genindex(const char *pkgdir) free(path); return errno; } - rv = repoidx_addpkg(binfile, dp->d_name, pkgdir); + rv = xbps_repo_addpkg_index(binfile, pkgdir); free(binfile); if (rv != 0) { (void)closedir(dirp); diff --git a/bin/xbps-repo/index.h b/bin/xbps-repo/index.h index 2de15618..43844d11 100644 --- a/bin/xbps-repo/index.h +++ b/bin/xbps-repo/index.h @@ -27,5 +27,6 @@ #define _XBPS_REPO_INDEX_H_ int xbps_repo_genindex(const char *); +int xbps_repo_addpkg_index(const char *, const char *); #endif /* !_XBPS_REPO_INDEX_H_ */ diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index cc281eb2..2dff5385 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -51,9 +51,10 @@ usage(void) { printf("Usage: xbps-repo [options] [action] [arguments]\n\n" " Available actions:\n" - " add, genindex, list, remove, search, show\n" + " add, add-pkgidx, genindex, list, remove, search, show\n" " Actions with arguments:\n" " add\t\t\n" + " add-pkgidx\t \n" " genindex\t\n" " remove\t\n" " search\t\n" @@ -68,7 +69,8 @@ usage(void) " $ xbps-repo remove /path/to/directory\n" " $ xbps-repo search klibc\n" " $ xbps-repo show klibc\n" - " $ xbps-repo genindex /path/to/packages/dir\n"); + " $ xbps-repo add-pkgidx /pkgdir /pkgdir/noarch/foo.xbps\n" + " $ xbps-repo genindex /pkgdir\n"); exit(EXIT_FAILURE); } @@ -280,6 +282,15 @@ main(int argc, char **argv) rv = xbps_repo_genindex(argv[1]); exit(rv); + } else if (strcasecmp(argv[0], "add-pkgidx") == 0) { + /* Add a binary package into a package repository. */ + if (argc != 3) + usage(); + + rv = xbps_repo_addpkg_index(argv[1], argv[2]); + if (rv != 0) + exit(rv); + } else { usage(); }