New pkg metadata structure for 0.18. See the NEWS file for info.
This commit is contained in:
@@ -2,9 +2,10 @@ TOPDIR = ../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
BIN = xbps-pkgdb
|
||||
OBJS = main.o check.o check_pkg_automatic.o check_pkg_files.o
|
||||
OBJS = main.o check.o check_pkg_files.o
|
||||
OBJS += check_pkg_requiredby.o check_pkg_rundeps.o
|
||||
OBJS += check_pkg_symlinks.o check_pkg_unneeded.o
|
||||
OBJS += convert.o
|
||||
|
||||
MAN = $(BIN).8
|
||||
|
||||
|
@@ -59,9 +59,6 @@ cb_pkg_integrity(struct xbps_handle *xhp,
|
||||
cpkg->npkgs, cpkg->totalpkgs, pkgname, version);
|
||||
if (check_pkg_integrity(xhp, obj, pkgname, false, &flush) != 0)
|
||||
cpkg->nbrokenpkgs++;
|
||||
else
|
||||
printf("\033[1A\033[K");
|
||||
|
||||
|
||||
if (flush && !cpkg->flush)
|
||||
cpkg->flush = flush;
|
||||
@@ -100,13 +97,16 @@ check_pkg_integrity(struct xbps_handle *xhp,
|
||||
bool flush,
|
||||
bool *setflush)
|
||||
{
|
||||
prop_dictionary_t opkgd, propsd, filesd;
|
||||
prop_dictionary_t opkgd, propsd;
|
||||
const char *sha256;
|
||||
char *buf;
|
||||
int rv = 0;
|
||||
bool pkgdb_update = false, broken = false;
|
||||
|
||||
propsd = filesd = opkgd = NULL;
|
||||
propsd = opkgd = NULL;
|
||||
|
||||
/* find real pkg by name */
|
||||
opkgd = pkgd;
|
||||
if (pkgd == NULL) {
|
||||
opkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
|
||||
if (opkgd == NULL) {
|
||||
@@ -122,27 +122,33 @@ check_pkg_integrity(struct xbps_handle *xhp,
|
||||
/*
|
||||
* Check for props.plist metadata file.
|
||||
*/
|
||||
propsd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGPROPS);
|
||||
propsd = xbps_pkgd_from_metadir(xhp, pkgname);
|
||||
if (propsd == NULL) {
|
||||
xbps_error_printf("%s: unexistent %s or invalid metadata "
|
||||
"file.\n", pkgname, XBPS_PKGPROPS);
|
||||
broken = true;
|
||||
goto out;
|
||||
printf("%s: unexistent metafile, converting to 0.18 "
|
||||
"format...\n", pkgname);
|
||||
if ((rv = convert_pkgd_metadir(xhp, opkgd)) != 0)
|
||||
goto out;
|
||||
|
||||
pkgdb_update = true;
|
||||
goto out1;
|
||||
} else if (prop_dictionary_count(propsd) == 0) {
|
||||
xbps_error_printf("%s: incomplete %s metadata file.\n",
|
||||
pkgname, XBPS_PKGPROPS);
|
||||
xbps_error_printf("%s: incomplete metadata file.\n", pkgname);
|
||||
broken = true;
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Check for files.plist metadata file.
|
||||
*/
|
||||
filesd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
|
||||
if (filesd == NULL) {
|
||||
xbps_error_printf("%s: unexistent %s or invalid metadata "
|
||||
"file.\n", pkgname, XBPS_PKGFILES);
|
||||
broken = true;
|
||||
goto out;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(opkgd, "metafile-sha256", &sha256);
|
||||
if (sha256 != NULL) {
|
||||
buf = xbps_xasprintf("%s/.%s.plist",
|
||||
xhp->metadir, pkgname);
|
||||
rv = xbps_file_hash_check(buf, sha256);
|
||||
free(buf);
|
||||
if (rv == ERANGE) {
|
||||
broken = true;
|
||||
fprintf(stderr, "%s: metadata file has been "
|
||||
"modified!\n", pkgname);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
#define RUN_PKG_CHECK(x, name, arg, arg2) \
|
||||
@@ -158,13 +164,13 @@ do { \
|
||||
} while (0)
|
||||
|
||||
/* Execute pkg checks */
|
||||
RUN_PKG_CHECK(xhp, files, filesd, &pkgdb_update);
|
||||
RUN_PKG_CHECK(xhp, symlinks, filesd, &pkgdb_update);
|
||||
RUN_PKG_CHECK(xhp, files, propsd, &pkgdb_update);
|
||||
RUN_PKG_CHECK(xhp, symlinks, propsd, &pkgdb_update);
|
||||
RUN_PKG_CHECK(xhp, rundeps, propsd, &pkgdb_update);
|
||||
RUN_PKG_CHECK(xhp, requiredby, pkgd ? pkgd : opkgd, &pkgdb_update);
|
||||
RUN_PKG_CHECK(xhp, autoinstall, pkgd ? pkgd : opkgd, &pkgdb_update);
|
||||
RUN_PKG_CHECK(xhp, unneeded, pkgd ? pkgd : opkgd, &pkgdb_update);
|
||||
RUN_PKG_CHECK(xhp, requiredby, opkgd, &pkgdb_update);
|
||||
RUN_PKG_CHECK(xhp, unneeded, opkgd, &pkgdb_update);
|
||||
|
||||
out1:
|
||||
if (flush && pkgdb_update) {
|
||||
if (!xbps_pkgdb_replace_pkgd(xhp, opkgd, pkgname, false, true)) {
|
||||
rv = EINVAL;
|
||||
@@ -177,8 +183,6 @@ do { \
|
||||
#undef RUN_PKG_CHECK
|
||||
|
||||
out:
|
||||
if (prop_object_type(filesd) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(filesd);
|
||||
if (prop_object_type(propsd) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(propsd);
|
||||
if (broken)
|
||||
|
@@ -1,77 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2011-2012 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 <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "defs.h"
|
||||
|
||||
/*
|
||||
* Checks package integrity of an installed package.
|
||||
* The following task is accomplished in this file:
|
||||
*
|
||||
* o Check if package was installed manually, but currently
|
||||
* other packages are depending on it. This package shall be
|
||||
* changed to automatic mode, i.e installed as dependency of
|
||||
* those packages.
|
||||
*
|
||||
* Returns 0 if test ran successfully, 1 otherwise and -1 on error.
|
||||
*/
|
||||
int
|
||||
check_pkg_autoinstall(struct xbps_handle *xhp,
|
||||
const char *pkgname,
|
||||
void *arg,
|
||||
bool *pkgdb_update)
|
||||
{
|
||||
prop_dictionary_t pkgd = arg;
|
||||
prop_array_t reqby;
|
||||
bool autoinst = false;
|
||||
|
||||
(void)xhp;
|
||||
/*
|
||||
* Check if package has been installed manually but any other
|
||||
* package is currently depending on it; in that case the package
|
||||
* must be in automatic mode.
|
||||
*/
|
||||
if (prop_dictionary_get_bool(pkgd, "automatic-install", &autoinst)) {
|
||||
reqby = prop_dictionary_get(pkgd, "requiredby");
|
||||
if (reqby != NULL && prop_array_count(reqby) && !autoinst) {
|
||||
/* pkg has reversedeps and was installed manually */
|
||||
prop_dictionary_set_bool(pkgd,
|
||||
"automatic-install", true);
|
||||
*pkgdb_update = true;
|
||||
printf("%s: changed to automatic install mode.\n",
|
||||
pkgname);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
@@ -65,8 +65,7 @@ check_reqby_pkg_cb(struct xbps_handle *xhp,
|
||||
* Internalize current pkg props dictionary from its
|
||||
* installed metadata directory.
|
||||
*/
|
||||
curpkg_propsd =
|
||||
xbps_dictionary_from_metadata_plist(xhp, curpkgn, XBPS_PKGPROPS);
|
||||
curpkg_propsd = xbps_pkgd_from_metadir(xhp, curpkgn);
|
||||
if (curpkg_propsd == NULL) {
|
||||
xbps_error_printf("%s: missing %s metadata file!\n",
|
||||
curpkgn, XBPS_PKGPROPS);
|
||||
|
173
bin/xbps-pkgdb/convert.c
Normal file
173
bin/xbps-pkgdb/convert.c
Normal file
@@ -0,0 +1,173 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 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_api.h>
|
||||
#include "defs.h"
|
||||
|
||||
static prop_data_t
|
||||
create_script_blob(struct xbps_handle *xhp,
|
||||
const char *file,
|
||||
const char *pkgname)
|
||||
{
|
||||
prop_data_t data;
|
||||
struct stat st;
|
||||
void *mf;
|
||||
char *buf;
|
||||
int fd;
|
||||
|
||||
buf = xbps_xasprintf("%s/metadata/%s/%s", xhp->metadir, pkgname, file);
|
||||
if ((fd = open(buf, O_RDONLY)) == -1) {
|
||||
free(buf);
|
||||
if (errno != ENOENT)
|
||||
fprintf(stderr, "%s: can't read INSTALL script: %s\n",
|
||||
pkgname, strerror(errno));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
if (stat(buf, &st) == -1) {
|
||||
free(buf);
|
||||
fprintf(stderr, "%s: failed to stat %s script: %s\n",
|
||||
pkgname, file, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
free(buf);
|
||||
|
||||
mf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (mf == MAP_FAILED) {
|
||||
close(fd);
|
||||
fprintf(stderr, "%s: failed to map INSTALL script: %s\n",
|
||||
pkgname, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
data = prop_data_create_data(mf, st.st_size);
|
||||
munmap(mf, st.st_size);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts package metadata format to 0.18.
|
||||
*/
|
||||
int
|
||||
convert_pkgd_metadir(struct xbps_handle *xhp, prop_dictionary_t pkgd)
|
||||
{
|
||||
prop_dictionary_t filesd, propsd;
|
||||
prop_array_t array;
|
||||
prop_data_t data;
|
||||
const char *pkgname;
|
||||
char *buf, *sha256, *propsf, *filesf;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname);
|
||||
|
||||
/* Merge XBPS_PKGFILES */
|
||||
propsf = xbps_xasprintf("%s/metadata/%s/%s", xhp->metadir,
|
||||
pkgname, XBPS_PKGPROPS);
|
||||
propsd = prop_dictionary_internalize_from_zfile(propsf);
|
||||
assert(propsd);
|
||||
|
||||
filesf = xbps_xasprintf("%s/metadata/%s/%s", xhp->metadir,
|
||||
pkgname, XBPS_PKGFILES);
|
||||
filesd = prop_dictionary_internalize_from_zfile(filesf);
|
||||
assert(filesd);
|
||||
|
||||
array = prop_dictionary_get(filesd, "files");
|
||||
if (array && prop_array_count(array))
|
||||
prop_dictionary_set(propsd, "files", array);
|
||||
|
||||
array = prop_dictionary_get(filesd, "conf_files");
|
||||
if (array && prop_array_count(array))
|
||||
prop_dictionary_set(propsd, "conf_files", array);
|
||||
|
||||
array = prop_dictionary_get(filesd, "dirs");
|
||||
if (array && prop_array_count(array))
|
||||
prop_dictionary_set(propsd, "dirs", array);
|
||||
|
||||
array = prop_dictionary_get(filesd, "links");
|
||||
if (array && prop_array_count(array))
|
||||
prop_dictionary_set(propsd, "links", array);
|
||||
|
||||
prop_object_release(filesd);
|
||||
|
||||
/* Merge INSTALL script */
|
||||
if ((data = create_script_blob(xhp, "INSTALL", pkgname))) {
|
||||
prop_dictionary_set(propsd, "install-script", data);
|
||||
prop_object_release(data);
|
||||
}
|
||||
/* Merge REMOVE script */
|
||||
if ((data = create_script_blob(xhp, "REMOVE", pkgname))) {
|
||||
prop_dictionary_set(propsd, "remove-script", data);
|
||||
prop_object_release(data);
|
||||
}
|
||||
/* Externalize pkg metaplist */
|
||||
buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
|
||||
if (!prop_dictionary_externalize_to_file(propsd, buf)) {
|
||||
fprintf(stderr, "%s: can't externalize plist: %s\n",
|
||||
pkgname, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
/* create sha256 hash for pkg plist */
|
||||
sha256 = xbps_file_hash(buf);
|
||||
free(buf);
|
||||
assert(sha256);
|
||||
prop_dictionary_set_cstring(pkgd, "metafile-sha256", sha256);
|
||||
free(sha256);
|
||||
|
||||
/* Remove old files/dir */
|
||||
if ((remove(propsf) == -1) || (remove(filesf) == -1))
|
||||
fprintf(stderr, "%s: failed to remove %s: %s\n",
|
||||
pkgname, propsf, strerror(errno));
|
||||
|
||||
buf = xbps_xasprintf("%s/metadata/%s/INSTALL", xhp->metadir, pkgname);
|
||||
if (access(buf, R_OK) == 0)
|
||||
remove(buf);
|
||||
free(buf);
|
||||
|
||||
buf = xbps_xasprintf("%s/metadata/%s/REMOVE", xhp->metadir, pkgname);
|
||||
if (access(buf, R_OK) == 0)
|
||||
remove(buf);
|
||||
free(buf);
|
||||
|
||||
buf = xbps_xasprintf("%s/metadata/%s", xhp->metadir, pkgname);
|
||||
remove(buf);
|
||||
free(buf);
|
||||
|
||||
buf = xbps_xasprintf("%s/metadata", xhp->metadir);
|
||||
remove(buf);
|
||||
free(buf);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -40,11 +40,13 @@ int check_pkg_integrity_all(struct xbps_handle *);
|
||||
#define CHECK_PKG_DECL(type) \
|
||||
int check_pkg_##type (struct xbps_handle *, const char *, void *, bool *)
|
||||
|
||||
CHECK_PKG_DECL(autoinstall);
|
||||
CHECK_PKG_DECL(unneeded);
|
||||
CHECK_PKG_DECL(files);
|
||||
CHECK_PKG_DECL(rundeps);
|
||||
CHECK_PKG_DECL(symlinks);
|
||||
CHECK_PKG_DECL(requiredby);
|
||||
|
||||
/* from convert.c */
|
||||
int convert_pkgd_metadir(struct xbps_handle *, prop_dictionary_t);
|
||||
|
||||
#endif /* !_XBPS_PKGDB_DEFS_H_ */
|
||||
|
Reference in New Issue
Block a user