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
This commit is contained in:
Juan RP 2009-08-18 14:12:44 +02:00
parent 5c07b001bc
commit ca9d72d460
3 changed files with 36 additions and 11 deletions

View File

@ -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", &regver);
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);

View File

@ -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_ */

View File

@ -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<URI>\n"
" add-pkgidx\t<repo> <binpkg>\n"
" genindex\t<path>\n"
" remove\t<URI>\n"
" search\t<string>\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();
}