Welcome pkgdb-0.38.

This commit is contained in:
Juan RP
2014-09-11 00:12:12 +02:00
parent fb9c94fab9
commit 01dbb968dd
30 changed files with 480 additions and 477 deletions

View File

@@ -508,7 +508,7 @@ main(int argc, char **argv)
/*
* Internalize the plist file of the target installed package.
*/
plistd = xbps_pkgdb_get_pkg_metadata(&xh, argv[0]);
plistd = xbps_pkgdb_get_pkg(&xh, argv[0]);
if (plistd == NULL)
die("cannot internalize %s metadata file", argv[0]);

View File

@@ -59,6 +59,9 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata _unused)
case XBPS_STATE_TRANS_CONFIGURE:
printf("\n[*] Configuring unpacked packages\n");
break;
case XBPS_STATE_PKGDB:
printf("[*] pkgdb upgrade in progress, please wait...\n");
break;
case XBPS_STATE_REPOSYNC:
printf("[*] Updating `%s' ...\n", xscd->arg);
break;
@@ -128,6 +131,10 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata _unused)
xscd->xhp->rootdir);
}
break;
case XBPS_STATE_PKGDB_DONE:
printf("The pkgdb file has been upgraded successfully, please reexec "
"the command again.\n");
break;
case XBPS_STATE_REPO_KEY_IMPORT:
printf("%s\n", xscd->desc);
printf("Fingerprint: %s\n", xscd->arg);

View File

@@ -281,9 +281,17 @@ exec_transaction(struct xbps_handle *xhp, int maxcols, bool yes, bool drun)
if ((rv = xbps_transaction_prepare(xhp)) != 0) {
if (rv == ENODEV) {
array = xbps_dictionary_get(xhp->transd, "missing_deps");
/* missing packages */
print_array(array);
fprintf(stderr, "Transaction aborted due to missing packages.\n");
if (xbps_array_count(array)) {
/* missing dependencies */
print_array(array);
fprintf(stderr, "Transaction aborted due to unresolved dependencies.\n");
}
array = xbps_dictionary_get(xhp->transd, "missing_shlibs");
if (xbps_array_count(array)) {
/* missing shlibs */
print_array(array);
fprintf(stderr, "Transaction aborted due to unresolved shlibs.\n");
}
goto out;
} else if (rv == EAGAIN) {
/* conflicts */

View File

@@ -5,6 +5,5 @@ BIN = xbps-pkgdb
OBJS = main.o check.o check_pkg_files.o
OBJS += check_pkg_rundeps.o
OBJS += check_pkg_symlinks.o check_pkg_unneeded.o
OBJS += convert.o
include $(TOPDIR)/mk/prog.mk

View File

@@ -72,12 +72,12 @@ check_pkg_integrity(struct xbps_handle *xhp,
xbps_dictionary_t pkgd,
const char *pkgname)
{
xbps_dictionary_t opkgd, propsd;
xbps_dictionary_t opkgd, filesd;
const char *sha256;
char *buf;
int rv = 0;
propsd = opkgd = NULL;
filesd = opkgd = NULL;
/* find real pkg by name */
opkgd = pkgd;
@@ -89,17 +89,17 @@ check_pkg_integrity(struct xbps_handle *xhp,
}
}
/*
* Check for props.plist metadata file.
* Check for pkg files metadata file.
*/
buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
propsd = xbps_dictionary_internalize_from_file(buf);
buf = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname);
filesd = xbps_dictionary_internalize_from_file(buf);
free(buf);
if (propsd == NULL) {
xbps_error_printf("%s: unexistent metafile!\n", pkgname);
if (filesd == NULL) {
xbps_error_printf("%s: unexistent files metafile!\n", pkgname);
return EINVAL;
} else if (xbps_dictionary_count(propsd) == 0) {
} else if (xbps_dictionary_count(filesd) == 0) {
xbps_error_printf("%s: incomplete metadata file.\n", pkgname);
xbps_object_release(propsd);
xbps_object_release(filesd);
return 1;
}
/*
@@ -107,12 +107,12 @@ check_pkg_integrity(struct xbps_handle *xhp,
*/
xbps_dictionary_get_cstring_nocopy(opkgd, "metafile-sha256", &sha256);
if (sha256 != NULL) {
buf = xbps_xasprintf("%s/.%s.plist",
buf = xbps_xasprintf("%s/.%s-files.plist",
xhp->metadir, pkgname);
rv = xbps_file_hash_check(buf, sha256);
free(buf);
if (rv == ERANGE) {
xbps_object_release(propsd);
xbps_object_release(filesd);
fprintf(stderr, "%s: metadata file has been "
"modified!\n", pkgname);
return 1;
@@ -130,12 +130,12 @@ do { \
} while (0)
/* Execute pkg checks */
RUN_PKG_CHECK(xhp, files, propsd);
RUN_PKG_CHECK(xhp, symlinks, propsd);
RUN_PKG_CHECK(xhp, rundeps, propsd);
RUN_PKG_CHECK(xhp, files, filesd);
RUN_PKG_CHECK(xhp, symlinks, filesd);
RUN_PKG_CHECK(xhp, rundeps, opkgd);
RUN_PKG_CHECK(xhp, unneeded, opkgd);
xbps_object_release(propsd);
xbps_object_release(filesd);
#undef RUN_PKG_CHECK

View File

@@ -1,117 +0,0 @@
/*-
* Copyright (c) 2013 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/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <assert.h>
#include <xbps.h>
#include "defs.h"
/*
* Convert pkgdb format to 0.21.
*/
static void
pkgdb_format_021(struct xbps_handle *xhp, const char *plist_new)
{
xbps_array_t array, rdeps;
xbps_dictionary_t pkgdb, pkgd;
char *pkgname, *plist;
plist = xbps_xasprintf("%s/pkgdb.plist", xhp->metadir);
if (access(plist, R_OK) == -1) {
if (errno == ENOENT) {
/* missing file, no conversion needed */
free(plist);
return;
}
xbps_error_printf("cannot read %s: %s\n",
plist, strerror(errno));
exit(EXIT_FAILURE);
}
array = xbps_array_internalize_from_zfile(plist);
if (xbps_object_type(array) != XBPS_TYPE_ARRAY) {
xbps_error_printf("unknown object type for %s\n",
plist, strerror(errno));
exit(EXIT_FAILURE);
}
pkgdb = xbps_dictionary_create();
assert(pkgdb);
for (unsigned int i = 0; i < xbps_array_count(array); i++) {
pkgd = xbps_array_get(array, i);
xbps_dictionary_get_cstring(pkgd, "pkgname", &pkgname);
rdeps = xbps_dictionary_get(pkgd, "run_depends");
/* remove unneeded objs */
xbps_dictionary_remove(pkgd, "pkgname");
xbps_dictionary_remove(pkgd, "version");
if (xbps_array_count(rdeps) == 0)
xbps_dictionary_remove(pkgd, "run_depends");
xbps_dictionary_set(pkgdb, pkgname, pkgd);
free(pkgname);
}
if (xbps_array_count(array) != xbps_dictionary_count(pkgdb)) {
xbps_error_printf("failed conversion! unmatched obj count "
"(got %zu, need %zu)\n", xbps_dictionary_count(pkgdb),
xbps_array_count(array));
exit(EXIT_FAILURE);
}
if (!xbps_dictionary_externalize_to_file(pkgdb, plist_new)) {
xbps_error_printf("failed to write %s: %s\n",
plist_new, strerror(errno));
exit(EXIT_FAILURE);
}
xbps_object_release(array);
xbps_object_release(pkgdb);
free(plist);
printf("Conversion to 0.21 pkgdb format successfully\n");
}
void
convert_pkgdb_format(struct xbps_handle *xhp)
{
char *plist;
plist = xbps_xasprintf("%s/%s", xhp->metadir, XBPS_PKGDB);
if ((access(plist, R_OK) == -1) && (errno == ENOENT))
pkgdb_format_021(xhp, plist);
free(plist);
}

View File

@@ -151,9 +151,10 @@ main(int argc, char **argv)
fprintf(stderr, "failed to lock pkgdb: %s\n", strerror(rv));
exit(EXIT_FAILURE);
}
if (update_format)
convert_pkgdb_format(&xh);
else if (instmode) {
if (update_format) {
/* nothing to do; xbps_pkgdb_lock() runs the conversion for us */
goto out;
} else if (instmode) {
if (argc == optind) {
fprintf(stderr,
"xbps-pkgdb: missing PKGNAME argument\n");
@@ -181,6 +182,7 @@ main(int argc, char **argv)
}
}
out:
xbps_pkgdb_unlock(&xh);
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
}

View File

@@ -103,7 +103,7 @@ ownedby_pkgdb_cb(struct xbps_handle *xhp,
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
pkgmetad = xbps_pkgdb_get_pkg_metadata(xhp, pkgver);
pkgmetad = xbps_pkgdb_get_pkg_files(xhp, pkgver);
assert(pkgmetad);
files_keys = xbps_dictionary_all_keys(pkgmetad);

View File

@@ -240,27 +240,12 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
const char *pkg,
const char *option)
{
xbps_array_t allkeys;
xbps_object_t obj, obj2;
xbps_dictionary_t d, pkgdb_d;
const char *key;
xbps_dictionary_t d;
pkgdb_d = xbps_pkgdb_get_pkg(xhp, pkg);
if (pkgdb_d == NULL)
return ENOENT;
d = xbps_pkgdb_get_pkg_metadata(xhp, pkg);
d = xbps_pkgdb_get_pkg(xhp, pkg);
if (d == NULL)
return ENOENT;
allkeys = xbps_dictionary_all_keys(pkgdb_d);
for (unsigned int i = 0; i < xbps_array_count(allkeys); i++) {
obj = xbps_array_get(allkeys, i);
obj2 = xbps_dictionary_get_keysym(pkgdb_d, obj);
key = xbps_dictionary_keysym_cstring_nocopy(obj);
xbps_dictionary_set(d, key, obj2);
}
if (option == NULL)
show_pkg_info(d);
else
@@ -275,7 +260,7 @@ show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
xbps_dictionary_t d;
int rv = 0;
d = xbps_pkgdb_get_pkg_metadata(xhp, pkg);
d = xbps_pkgdb_get_pkg_files(xhp, pkg);
if (d == NULL)
return ENOENT;