New pkg metadata structure for 0.18. See the NEWS file for info.

This commit is contained in:
Juan RP 2012-11-16 16:55:35 +01:00
parent db4b542d40
commit 34bd49f85a
28 changed files with 672 additions and 534 deletions

18
NEWS
View File

@ -1,5 +1,23 @@
xbps-0.18 (???): xbps-0.18 (???):
* Structured pkg metadata stored on disk, and added new functionality:
- A single plist containing pkg properties, files and
INSTALL/REMOVE scripts added as prop_data(3) objects.
- pkgdb's pkg dictionary now contains a sha256 hash to know if the
plist from metadir has been modified.
- prop_data(3) objects can be seen with xbps-query(8) --property.
- pkg plists are now kept in <metadir>/.<pkgname>.plist.
- In a future revision libxbps could make a backup of pkgdb and
plist files in metadir before a transaction is committed.
Users must run 'xbps-pkgdb [-r <rootdir>] -a' to upgrade pkg metadata
to the 0.18 format.
* Shell wildcard patterns (fnmatch(3)) can now be used in the * Shell wildcard patterns (fnmatch(3)) can now be used in the
PackagesOnHold configuration option. PackagesOnHold configuration option.

View File

@ -510,9 +510,9 @@ main(int argc, char **argv)
/* /*
* Internalize the plist file of the target installed package. * Internalize the plist file of the target installed package.
*/ */
plistd = xbps_dictionary_from_metadata_plist(&xh, argv[0], XBPS_PKGPROPS); plistd = xbps_pkgd_from_metadir(&xh, argv[0]);
if (plistd == NULL) if (plistd == NULL)
die("cannot internalize %s from %s", XBPS_PKGPROPS, argv[0]); die("cannot internalize %s metadata file", argv[0]);
/* /*
* Create the output FILE. * Create the output FILE.

View File

@ -173,8 +173,6 @@ main(int argc, char **argv)
xh.repository = defrepo; xh.repository = defrepo;
if (flags & XBPS_FLAG_VERBOSE) if (flags & XBPS_FLAG_VERBOSE)
xh.unpack_cb = unpack_progress_cb_verbose; xh.unpack_cb = unpack_progress_cb_verbose;
else
xh.unpack_cb = unpack_progress_cb;
if ((rv = xbps_init(&xh)) != 0) { if ((rv = xbps_init(&xh)) != 0) {
xbps_error_printf("Failed to initialize libxbps: %s\n", xbps_error_printf("Failed to initialize libxbps: %s\n",

View File

@ -49,46 +49,48 @@ state_cb(struct xbps_handle *xhp,
switch (xscd->state) { switch (xscd->state) {
/* notifications */ /* notifications */
case XBPS_STATE_TRANS_DOWNLOAD: case XBPS_STATE_TRANS_DOWNLOAD:
printf("[*] Downloading binary packages\n"); printf("\n[*] Downloading binary packages\n");
break; break;
case XBPS_STATE_TRANS_VERIFY: case XBPS_STATE_TRANS_VERIFY:
printf("[*] Verifying binary package integrity\n"); printf("\n[*] Verifying binary package integrity\n");
break; break;
case XBPS_STATE_TRANS_RUN: case XBPS_STATE_TRANS_RUN:
printf("[*] Running transaction tasks\n"); printf("\n[*] Running transaction tasks\n");
break; break;
case XBPS_STATE_TRANS_CONFIGURE: case XBPS_STATE_TRANS_CONFIGURE:
printf("[*] Configuring unpacked packages\n"); printf("\n[*] Configuring unpacked packages\n");
break; break;
case XBPS_STATE_REPOSYNC: case XBPS_STATE_REPOSYNC:
printf("[*] Updating `%s/%s' ...\n", printf("[*] Updating `%s/%s' ...\n",
xscd->arg0, xscd->arg1); xscd->arg0, xscd->arg1);
break; break;
case XBPS_STATE_VERIFY: case XBPS_STATE_VERIFY:
printf("%s: checking binary pkg integrity ...\n", xscd->arg0);
break;
case XBPS_STATE_CONFIG_FILE: case XBPS_STATE_CONFIG_FILE:
if (xscd->desc != NULL) if (xscd->desc != NULL)
printf("%s\n", xscd->desc); printf("%s\n", xscd->desc);
break; break;
case XBPS_STATE_REMOVE: case XBPS_STATE_REMOVE:
printf("Removing `%s-%s' ...\n", xscd->arg0, xscd->arg1); printf("%s-%s: removing ...\n", xscd->arg0, xscd->arg1);
break; break;
case XBPS_STATE_CONFIGURE: case XBPS_STATE_CONFIGURE:
printf("Configuring `%s-%s' ...\n", xscd->arg0, xscd->arg1); printf("%s-%s: configuring ...\n", xscd->arg0, xscd->arg1);
break; break;
case XBPS_STATE_REGISTER: case XBPS_STATE_REGISTER:
case XBPS_STATE_UNREGISTER: case XBPS_STATE_UNREGISTER:
/* empty */ /* empty */
break; break;
case XBPS_STATE_UNPACK: case XBPS_STATE_UNPACK:
printf("Unpacking `%s-%s' ...\n", xscd->arg0, xscd->arg1); printf("%s-%s: unpacking ...\n", xscd->arg0, xscd->arg1);
break; break;
case XBPS_STATE_INSTALL: case XBPS_STATE_INSTALL:
printf("Installing `%s-%s' ...\n", xscd->arg0, xscd->arg1); printf("%s-%s: installing ...\n", xscd->arg0, xscd->arg1);
break; break;
case XBPS_STATE_UPDATE: case XBPS_STATE_UPDATE:
pkgd = xbps_find_pkg_dict_installed(xhp, xscd->arg0, false); pkgd = xbps_find_pkg_dict_installed(xhp, xscd->arg0, false);
prop_dictionary_get_cstring_nocopy(pkgd, "version", &version); prop_dictionary_get_cstring_nocopy(pkgd, "version", &version);
printf("Updating `%s' (`%s' to `%s') ...\n", xscd->arg0, printf("%s-%s: updating to %s ...\n", xscd->arg0,
version, xscd->arg1); version, xscd->arg1);
break; break;
/* success */ /* success */
@ -102,7 +104,7 @@ state_cb(struct xbps_handle *xhp,
} }
break; break;
case XBPS_STATE_INSTALL_DONE: case XBPS_STATE_INSTALL_DONE:
printf("Installed `%s-%s' successfully.\n", printf("%s-%s: installed successfully.\n",
xscd->arg0, xscd->arg1); xscd->arg0, xscd->arg1);
if (syslog_enabled) if (syslog_enabled)
syslog(LOG_NOTICE, "Installed `%s-%s' successfully " syslog(LOG_NOTICE, "Installed `%s-%s' successfully "
@ -110,7 +112,7 @@ state_cb(struct xbps_handle *xhp,
xhp->rootdir); xhp->rootdir);
break; break;
case XBPS_STATE_UPDATE_DONE: case XBPS_STATE_UPDATE_DONE:
printf("Updated `%s' to `%s' successfully.\n", printf("%s-%s: updated successfully.\n",
xscd->arg0, xscd->arg1); xscd->arg0, xscd->arg1);
if (syslog_enabled) if (syslog_enabled)
syslog(LOG_NOTICE, "Updated `%s' to `%s' successfully " syslog(LOG_NOTICE, "Updated `%s' to `%s' successfully "
@ -118,7 +120,7 @@ state_cb(struct xbps_handle *xhp,
xhp->rootdir); xhp->rootdir);
break; break;
case XBPS_STATE_REMOVE_DONE: case XBPS_STATE_REMOVE_DONE:
printf("Removed `%s-%s' successfully.\n", printf("%s-%s: removed successfully.\n",
xscd->arg0, xscd->arg1); xscd->arg0, xscd->arg1);
if (syslog_enabled) if (syslog_enabled)
syslog(LOG_NOTICE, "Removed `%s-%s' successfully " syslog(LOG_NOTICE, "Removed `%s-%s' successfully "

View File

@ -314,7 +314,7 @@ exec_transaction(struct xbps_handle *xhp, size_t maxcols, bool yes, bool drun)
* It's time to run the transaction! * It's time to run the transaction!
*/ */
if ((rv = xbps_transaction_commit(xhp)) == 0) { if ((rv = xbps_transaction_commit(xhp)) == 0) {
printf("%u installed, %u updated, " printf("\n%u installed, %u updated, "
"%u configured, %u removed.\n", trans->inst_pkgcnt, "%u configured, %u removed.\n", trans->inst_pkgcnt,
trans->up_pkgcnt, trans->cf_pkgcnt + trans->inst_pkgcnt, trans->up_pkgcnt, trans->cf_pkgcnt + trans->inst_pkgcnt,
trans->rm_pkgcnt); trans->rm_pkgcnt);

View File

@ -2,9 +2,10 @@ TOPDIR = ../..
-include $(TOPDIR)/config.mk -include $(TOPDIR)/config.mk
BIN = xbps-pkgdb 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_requiredby.o check_pkg_rundeps.o
OBJS += check_pkg_symlinks.o check_pkg_unneeded.o OBJS += check_pkg_symlinks.o check_pkg_unneeded.o
OBJS += convert.o
MAN = $(BIN).8 MAN = $(BIN).8

View File

@ -59,9 +59,6 @@ cb_pkg_integrity(struct xbps_handle *xhp,
cpkg->npkgs, cpkg->totalpkgs, pkgname, version); cpkg->npkgs, cpkg->totalpkgs, pkgname, version);
if (check_pkg_integrity(xhp, obj, pkgname, false, &flush) != 0) if (check_pkg_integrity(xhp, obj, pkgname, false, &flush) != 0)
cpkg->nbrokenpkgs++; cpkg->nbrokenpkgs++;
else
printf("\033[1A\033[K");
if (flush && !cpkg->flush) if (flush && !cpkg->flush)
cpkg->flush = flush; cpkg->flush = flush;
@ -100,13 +97,16 @@ check_pkg_integrity(struct xbps_handle *xhp,
bool flush, bool flush,
bool *setflush) bool *setflush)
{ {
prop_dictionary_t opkgd, propsd, filesd; prop_dictionary_t opkgd, propsd;
const char *sha256;
char *buf;
int rv = 0; int rv = 0;
bool pkgdb_update = false, broken = false; bool pkgdb_update = false, broken = false;
propsd = filesd = opkgd = NULL; propsd = opkgd = NULL;
/* find real pkg by name */ /* find real pkg by name */
opkgd = pkgd;
if (pkgd == NULL) { if (pkgd == NULL) {
opkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false); opkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
if (opkgd == NULL) { if (opkgd == NULL) {
@ -122,27 +122,33 @@ check_pkg_integrity(struct xbps_handle *xhp,
/* /*
* Check for props.plist metadata file. * 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) { if (propsd == NULL) {
xbps_error_printf("%s: unexistent %s or invalid metadata " printf("%s: unexistent metafile, converting to 0.18 "
"file.\n", pkgname, XBPS_PKGPROPS); "format...\n", pkgname);
broken = true; if ((rv = convert_pkgd_metadir(xhp, opkgd)) != 0)
goto out; goto out;
pkgdb_update = true;
goto out1;
} else if (prop_dictionary_count(propsd) == 0) { } else if (prop_dictionary_count(propsd) == 0) {
xbps_error_printf("%s: incomplete %s metadata file.\n", xbps_error_printf("%s: incomplete metadata file.\n", pkgname);
pkgname, XBPS_PKGPROPS);
broken = true; broken = true;
goto out; goto out;
} }
/*
* Check for files.plist metadata file. prop_dictionary_get_cstring_nocopy(opkgd, "metafile-sha256", &sha256);
*/ if (sha256 != NULL) {
filesd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES); buf = xbps_xasprintf("%s/.%s.plist",
if (filesd == NULL) { xhp->metadir, pkgname);
xbps_error_printf("%s: unexistent %s or invalid metadata " rv = xbps_file_hash_check(buf, sha256);
"file.\n", pkgname, XBPS_PKGFILES); free(buf);
broken = true; if (rv == ERANGE) {
goto out; broken = true;
fprintf(stderr, "%s: metadata file has been "
"modified!\n", pkgname);
goto out;
}
} }
#define RUN_PKG_CHECK(x, name, arg, arg2) \ #define RUN_PKG_CHECK(x, name, arg, arg2) \
@ -158,13 +164,13 @@ do { \
} while (0) } while (0)
/* Execute pkg checks */ /* Execute pkg checks */
RUN_PKG_CHECK(xhp, files, filesd, &pkgdb_update); RUN_PKG_CHECK(xhp, files, propsd, &pkgdb_update);
RUN_PKG_CHECK(xhp, symlinks, filesd, &pkgdb_update); RUN_PKG_CHECK(xhp, symlinks, propsd, &pkgdb_update);
RUN_PKG_CHECK(xhp, rundeps, 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, requiredby, opkgd, &pkgdb_update);
RUN_PKG_CHECK(xhp, autoinstall, pkgd ? pkgd : opkgd, &pkgdb_update); RUN_PKG_CHECK(xhp, unneeded, opkgd, &pkgdb_update);
RUN_PKG_CHECK(xhp, unneeded, pkgd ? pkgd : opkgd, &pkgdb_update);
out1:
if (flush && pkgdb_update) { if (flush && pkgdb_update) {
if (!xbps_pkgdb_replace_pkgd(xhp, opkgd, pkgname, false, true)) { if (!xbps_pkgdb_replace_pkgd(xhp, opkgd, pkgname, false, true)) {
rv = EINVAL; rv = EINVAL;
@ -177,8 +183,6 @@ do { \
#undef RUN_PKG_CHECK #undef RUN_PKG_CHECK
out: out:
if (prop_object_type(filesd) == PROP_TYPE_DICTIONARY)
prop_object_release(filesd);
if (prop_object_type(propsd) == PROP_TYPE_DICTIONARY) if (prop_object_type(propsd) == PROP_TYPE_DICTIONARY)
prop_object_release(propsd); prop_object_release(propsd);
if (broken) if (broken)

View File

@ -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;
}

View File

@ -65,8 +65,7 @@ check_reqby_pkg_cb(struct xbps_handle *xhp,
* Internalize current pkg props dictionary from its * Internalize current pkg props dictionary from its
* installed metadata directory. * installed metadata directory.
*/ */
curpkg_propsd = curpkg_propsd = xbps_pkgd_from_metadir(xhp, curpkgn);
xbps_dictionary_from_metadata_plist(xhp, curpkgn, XBPS_PKGPROPS);
if (curpkg_propsd == NULL) { if (curpkg_propsd == NULL) {
xbps_error_printf("%s: missing %s metadata file!\n", xbps_error_printf("%s: missing %s metadata file!\n",
curpkgn, XBPS_PKGPROPS); curpkgn, XBPS_PKGPROPS);

173
bin/xbps-pkgdb/convert.c Normal file
View 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;
}

View File

@ -40,11 +40,13 @@ int check_pkg_integrity_all(struct xbps_handle *);
#define CHECK_PKG_DECL(type) \ #define CHECK_PKG_DECL(type) \
int check_pkg_##type (struct xbps_handle *, const char *, void *, bool *) int check_pkg_##type (struct xbps_handle *, const char *, void *, bool *)
CHECK_PKG_DECL(autoinstall);
CHECK_PKG_DECL(unneeded); CHECK_PKG_DECL(unneeded);
CHECK_PKG_DECL(files); CHECK_PKG_DECL(files);
CHECK_PKG_DECL(rundeps); CHECK_PKG_DECL(rundeps);
CHECK_PKG_DECL(symlinks); CHECK_PKG_DECL(symlinks);
CHECK_PKG_DECL(requiredby); CHECK_PKG_DECL(requiredby);
/* from convert.c */
int convert_pkgd_metadir(struct xbps_handle *, prop_dictionary_t);
#endif /* !_XBPS_PKGDB_DEFS_H_ */ #endif /* !_XBPS_PKGDB_DEFS_H_ */

View File

@ -34,6 +34,12 @@
#include <xbps_api.h> #include <xbps_api.h>
#include "defs.h" #include "defs.h"
struct ffdata {
int npatterns;
char **patterns;
const char *repouri;
};
static int static int
match_files_by_pattern(prop_dictionary_t pkg_filesd, match_files_by_pattern(prop_dictionary_t pkg_filesd,
prop_dictionary_keysym_t key, prop_dictionary_keysym_t key,
@ -48,7 +54,6 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd,
int i; int i;
keyname = prop_dictionary_keysym_cstring_nocopy(key); keyname = prop_dictionary_keysym_cstring_nocopy(key);
array = prop_dictionary_get_keysym(pkg_filesd, key);
if (strcmp(keyname, "files") == 0) if (strcmp(keyname, "files") == 0)
typestr = "regular file"; typestr = "regular file";
@ -56,10 +61,14 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd,
typestr = "directory"; typestr = "directory";
else if (strcmp(keyname, "links") == 0) else if (strcmp(keyname, "links") == 0)
typestr = "link"; typestr = "link";
else else if (strcmp(keyname, "conf_files") == 0)
typestr = "configuration file"; typestr = "configuration file";
else
return 0;
array = prop_dictionary_get_keysym(pkg_filesd, key);
iter = prop_array_iterator(array); iter = prop_array_iterator(array);
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "file", &filestr); prop_dictionary_get_cstring_nocopy(obj, "file", &filestr);
for (i = 0; i < npatterns; i++) { for (i = 0; i < npatterns; i++) {
@ -73,61 +82,45 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd,
return 0; return 0;
} }
int static int
ownedby(struct xbps_handle *xhp, int npatterns, char **patterns) ownedby_pkgdb_cb(struct xbps_handle *xhp, prop_object_t obj, void *arg, bool *done)
{ {
prop_dictionary_t pkg_filesd; prop_dictionary_t pkgmetad;
prop_array_t files_keys; prop_array_t files_keys;
DIR *dirp; struct ffdata *ffd = arg;
struct dirent *dp; unsigned int i;
char *path; const char *pkgname;
int rv = 0; int rv = 0;
unsigned int i, count;
path = xbps_xasprintf("%s/metadata", xhp->metadir); (void)done;
if ((dirp = opendir(path)) == NULL) {
free(path);
return -1;
}
while ((dp = readdir(dirp)) != NULL) { prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if ((strcmp(dp->d_name, ".") == 0) || pkgmetad = xbps_pkgd_from_metadir(xhp, pkgname);
(strcmp(dp->d_name, "..") == 0))
continue;
pkg_filesd = xbps_dictionary_from_metadata_plist(xhp, files_keys = prop_dictionary_all_keys(pkgmetad);
dp->d_name, XBPS_PKGFILES); for (i = 0; i < prop_array_count(files_keys); i++) {
if (pkg_filesd == NULL) { rv = match_files_by_pattern(pkgmetad,
if (errno == ENOENT) prop_array_get(files_keys, i),
continue; ffd->npatterns, ffd->patterns, pkgname);
rv = -1;
break;
}
files_keys = prop_dictionary_all_keys(pkg_filesd);
count = prop_array_count(files_keys);
for (i = 0; i < count; i++) {
rv = match_files_by_pattern(pkg_filesd,
prop_array_get(files_keys, i),
npatterns, patterns, dp->d_name);
if (rv == -1)
break;
}
prop_object_release(files_keys);
prop_object_release(pkg_filesd);
if (rv == -1) if (rv == -1)
break; break;
} }
(void)closedir(dirp); prop_object_release(files_keys);
free(path); prop_object_release(pkgmetad);
return rv; return rv;
} }
struct ffdata { int
int npatterns; ownedby(struct xbps_handle *xhp, int npatterns, char **patterns)
char **patterns; {
const char *repouri; struct ffdata ffd;
};
ffd.npatterns = npatterns;
ffd.patterns = patterns;
return xbps_pkgdb_foreach_cb(xhp, ownedby_pkgdb_cb, &ffd);
}
static void static void
repo_match_files_by_pattern(struct xbps_handle *xhp, repo_match_files_by_pattern(struct xbps_handle *xhp,

View File

@ -44,8 +44,7 @@ show_pkg_deps(struct xbps_handle *xhp, const char *pkgname)
/* /*
* Check for props.plist metadata file. * Check for props.plist metadata file.
*/ */
propsd = xbps_dictionary_from_metadata_plist(xhp, propsd = xbps_pkgd_from_metadir(xhp, pkgname);
pkgname, XBPS_PKGPROPS);
if (propsd == NULL) if (propsd == NULL)
return ENOENT; return ENOENT;

View File

@ -31,26 +31,33 @@
#include <limits.h> #include <limits.h>
#include <libgen.h> #include <libgen.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <assert.h>
#include <xbps_api.h> #include <xbps_api.h>
#include "defs.h" #include "defs.h"
static void static void
print_value_obj(const char *keyname, prop_object_t obj, bool raw) print_value_obj(const char *keyname, prop_object_t obj,
const char *indent, bool raw)
{ {
const char *value; prop_array_t allkeys;
prop_object_t obj2, keysym;
const char *ksymname, *value;
size_t i; size_t i;
char size[8]; char size[8];
if (indent == NULL)
indent = "";
switch (prop_object_type(obj)) { switch (prop_object_type(obj)) {
case PROP_TYPE_STRING: case PROP_TYPE_STRING:
if (!raw) if (!raw)
printf("%s: ", keyname); printf("%s%s: ", indent, keyname);
printf("%s\n", prop_string_cstring_nocopy(obj)); printf("%s\n", prop_string_cstring_nocopy(obj));
break; break;
case PROP_TYPE_NUMBER: case PROP_TYPE_NUMBER:
if (!raw) if (!raw)
printf("%s: ", keyname); printf("%s%s: ", indent, keyname);
if (xbps_humanize_number(size, if (xbps_humanize_number(size,
(int64_t)prop_number_unsigned_integer_value(obj)) == -1) (int64_t)prop_number_unsigned_integer_value(obj)) == -1)
printf("%ju\n", printf("%ju\n",
@ -60,20 +67,53 @@ print_value_obj(const char *keyname, prop_object_t obj, bool raw)
break; break;
case PROP_TYPE_BOOL: case PROP_TYPE_BOOL:
if (!raw) if (!raw)
printf("%s: ", keyname); printf("%s%s: ", indent, keyname);
printf("%s\n", prop_bool_true(obj) ? "yes" : "no"); printf("%s\n", prop_bool_true(obj) ? "yes" : "no");
break; break;
case PROP_TYPE_ARRAY: case PROP_TYPE_ARRAY:
if (!raw) if (!raw)
printf("%s:\n", keyname); printf("%s%s:\n", indent, keyname);
for (i = 0; i < prop_array_count(obj); i++) { for (i = 0; i < prop_array_count(obj); i++) {
prop_array_get_cstring_nocopy(obj, i, &value); obj2 = prop_array_get(obj, i);
printf("%s%s%s", !raw ? "\t" : "", value, if (prop_object_type(obj2) == PROP_TYPE_STRING) {
!raw ? "\n" : " "); value = prop_string_cstring_nocopy(obj2);
printf("%s%s%s%s", indent, !raw ? "\t" : "",
value, !raw ? "\n" : "");
} else {
print_value_obj(keyname, obj2, " ", raw);
}
} }
if (raw) if (raw)
printf("\n"); printf("\n");
break; break;
case PROP_TYPE_DICTIONARY:
allkeys = prop_dictionary_all_keys(obj);
for (i = 0; i < prop_array_count(allkeys); i++) {
keysym = prop_array_get(allkeys, i);
ksymname = prop_dictionary_keysym_cstring_nocopy(keysym);
obj2 = prop_dictionary_get_keysym(obj, keysym);
print_value_obj(ksymname, obj2, " ", raw);
}
prop_object_release(allkeys);
if (raw)
printf("\n");
break;
case PROP_TYPE_DATA:
if (!raw) {
xbps_humanize_number(size, (int64_t)prop_data_size(obj));
printf("%s%s: %s\n", indent, keyname, size);
} else {
FILE *f;
char buf[BUFSIZ-1];
f = fmemopen(prop_data_data(obj),
prop_data_size(obj), "r");
assert(f);
while (fgets(buf, BUFSIZ-1, f))
printf("%s", buf);
fclose(f);
}
break;
default: default:
xbps_warn_printf("unknown obj type (key %s)\n", xbps_warn_printf("unknown obj type (key %s)\n",
keyname); keyname);
@ -91,7 +131,7 @@ show_pkg_info_one(prop_dictionary_t d, const char *keys)
obj = prop_dictionary_get(d, keys); obj = prop_dictionary_get(d, keys);
if (obj == NULL) if (obj == NULL)
return; return;
print_value_obj(keys, obj, true); print_value_obj(keys, obj, NULL, true);
return; return;
} }
key = strdup(keys); key = strdup(keys);
@ -102,7 +142,7 @@ show_pkg_info_one(prop_dictionary_t d, const char *keys)
obj = prop_dictionary_get(d, p); obj = prop_dictionary_get(d, p);
if (obj == NULL) if (obj == NULL)
continue; continue;
print_value_obj(p, obj, true); print_value_obj(p, obj, NULL, true);
} }
free(key); free(key);
} }
@ -120,11 +160,15 @@ show_pkg_info(prop_dictionary_t dict)
keysym = prop_array_get(all_keys, i); keysym = prop_array_get(all_keys, i);
keyname = prop_dictionary_keysym_cstring_nocopy(keysym); keyname = prop_dictionary_keysym_cstring_nocopy(keysym);
obj = prop_dictionary_get_keysym(dict, keysym); obj = prop_dictionary_get_keysym(dict, keysym);
/* ignore run_depends, it's shown via 'show-deps' */ /* ignore objs shown by other targets */
if (strcmp(keyname, "run_depends") == 0) if ((strcmp(keyname, "run_depends") == 0) ||
(strcmp(keyname, "requiredby") == 0) ||
(strcmp(keyname, "files") == 0) ||
(strcmp(keyname, "dirs") == 0) ||
(strcmp(keyname, "links") == 0))
continue; continue;
print_value_obj(keyname, obj, false); print_value_obj(keyname, obj, NULL, false);
} }
prop_object_release(all_keys); prop_object_release(all_keys);
} }
@ -142,7 +186,9 @@ show_pkg_files(prop_dictionary_t filesd)
for (i = 0; i < prop_array_count(allkeys); i++) { for (i = 0; i < prop_array_count(allkeys); i++) {
ksym = prop_array_get(allkeys, i); ksym = prop_array_get(allkeys, i);
keyname = prop_dictionary_keysym_cstring_nocopy(ksym); keyname = prop_dictionary_keysym_cstring_nocopy(ksym);
if (strcmp(keyname, "dirs") == 0) if ((strcmp(keyname, "files") &&
(strcmp(keyname, "conf_files") &&
(strcmp(keyname, "links")))))
continue; continue;
array = prop_dictionary_get(filesd, keyname); array = prop_dictionary_get(filesd, keyname);
@ -174,7 +220,7 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
const char *instdate, *pname; const char *instdate, *pname;
bool autoinst; bool autoinst;
d = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGPROPS); d = xbps_pkgd_from_metadir(xhp, pkgname);
if (d == NULL) if (d == NULL)
return ENOENT; return ENOENT;
@ -207,7 +253,7 @@ show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkgname)
prop_dictionary_t d; prop_dictionary_t d;
int rv = 0; int rv = 0;
d = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES); d = xbps_pkgd_from_metadir(xhp, pkgname);
if (d == NULL) if (d == NULL)
return ENOENT; return ENOENT;

View File

@ -65,7 +65,7 @@ state_cb(struct xbps_handle *xhp, struct xbps_state_cb_data *xscd, void *cbd)
switch (xscd->state) { switch (xscd->state) {
/* notifications */ /* notifications */
case XBPS_STATE_CONFIGURE: case XBPS_STATE_CONFIGURE:
printf("Configuring `%s-%s' ...\n", xscd->arg0, xscd->arg1); printf("%s-%s: configuraring ...\n", xscd->arg0, xscd->arg1);
break; break;
/* errors */ /* errors */
case XBPS_STATE_CONFIGURE_FAIL: case XBPS_STATE_CONFIGURE_FAIL:

View File

@ -56,7 +56,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.5" #define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20121111-1" #define XBPS_API_VERSION "20121116"
#ifndef XBPS_VERSION #ifndef XBPS_VERSION
#define XBPS_VERSION "UNSET" #define XBPS_VERSION "UNSET"
@ -1204,19 +1204,51 @@ prop_object_iterator_t xbps_array_iter_from_dict(prop_dictionary_t dict,
const char *key); const char *key);
/** /**
* Returns a proplib object dictionary associated with the installed package * Returns a proplib dictionary associated with the installed package
* \a pkgname, by internalizing its plist file defined in \a plist. * \a name, by internalizing its plist file from metadir.
* *
* @param[in] xhp The pointer to the xbps_handle struct. * @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] pkgname Package name of installed package. * @param[in] name Package name of installed package.
* @param[in] plist Package metadata property list file.
* *
* @return The proplib object dictionary on success, NULL otherwise and * @return The proplib dictionary on success, NULL otherwise and
* errno is set appropiately. * errno is set appropiately.
*/ */
prop_dictionary_t xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp, prop_dictionary_t xbps_pkgd_from_metadir(struct xbps_handle *xhp,
const char *pkgname, const char *name);
const char *plist);
/**
* Creates a temporary file and executes it in rootdir.
*
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] blob The buffer pointer where the data is stored.
* @param[in] blobsiz The size of the buffer data.
* @param[in] pkgname The package name associated.
* @param[in] version The package version associated.
* @param[in] action The action to execute on the temporary file.
* @param[in] update Set to true if package is being updated.
*/
int xbps_pkg_exec_buffer(struct xbps_handle *xhp,
const void *blob,
const size_t blobsiz,
const char *pkgname,
const char *version,
const char *action,
bool update);
/**
* Creates a temporary file and executes it in rootdir.
*
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] d Package dictionary where the script data is stored.
* @param[in] script Key associated with the script in dictionary.
* @param[in] action The action to execute on the temporary file.
* @param[in] update Set to true if package is being updated.
*/
int xbps_pkg_exec_script(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *script,
const char *action,
bool update);
/** /**
* Removes the package's proplib dictionary matching \a pkgname * Removes the package's proplib dictionary matching \a pkgname

View File

@ -44,6 +44,7 @@ EXTOBJS += external/mkpath.o
OBJS = package_configure.o package_config_files.o package_orphans.o OBJS = package_configure.o package_config_files.o package_orphans.o
OBJS += package_remove.o package_remove_obsoletes.o package_state.o OBJS += package_remove.o package_remove_obsoletes.o package_state.o
OBJS += package_unpack.o package_requiredby.o package_register.o OBJS += package_unpack.o package_requiredby.o package_register.o
OBJS += package_script.o
OBJS += transaction_commit.o transaction_package_replace.o OBJS += transaction_commit.o transaction_package_replace.o
OBJS += transaction_dictionary.o transaction_sortdeps.o transaction_ops.o OBJS += transaction_dictionary.o transaction_sortdeps.o transaction_ops.o
OBJS += download.o initend.o pkgdb.o package_conflicts.o OBJS += download.o initend.o pkgdb.o package_conflicts.o

View File

@ -91,11 +91,12 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
xbps_dbg_printf(xhp, "%s-%s: processing conf_file %s\n", xbps_dbg_printf(xhp, "%s-%s: processing conf_file %s\n",
pkgname, version, entry_pname); pkgname, version, entry_pname);
forigd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES); forigd = xbps_pkgd_from_metadir(xhp, pkgname);
if (forigd == NULL) { if (forigd == NULL) {
xbps_dbg_printf(xhp, "%s-%s: conf_file %s not currently " xbps_dbg_printf(xhp, "%s-%s: conf_file %s not currently "
"installed\n", pkgname, version, entry_pname); "installed\n", pkgname, version, entry_pname);
rv = 1; rv = 1;
prop_object_release(forigd);
goto out; goto out;
} }

View File

@ -77,9 +77,8 @@ xbps_configure_pkg(struct xbps_handle *xhp,
bool update, bool update,
bool flush) bool flush)
{ {
prop_dictionary_t pkgd; prop_dictionary_t pkgd, pkgmetad;
const char *version, *pkgver; const char *version, *pkgver;
char *buf;
int rv = 0; int rv = 0;
pkg_state_t state = 0; pkg_state_t state = 0;
@ -111,39 +110,19 @@ xbps_configure_pkg(struct xbps_handle *xhp,
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL); xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL);
buf = xbps_xasprintf("%s/metadata/%s/INSTALL", pkgmetad = xbps_pkgd_from_metadir(xhp, pkgname);
XBPS_META_PATH, pkgname); assert(pkgmetad);
if (chdir(xhp->rootdir) == -1) {
rv = xbps_pkg_exec_script(xhp, pkgmetad, "install-script", "post", update);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [configure] failed to chdir to rootdir `%s': %s", "%s: [configure] INSTALL script failed to execute "
pkgver, xhp->rootdir, strerror(errno)); "the post ACTION: %s", pkgver, strerror(rv));
free(buf); prop_object_release(pkgmetad);
return EINVAL; return rv;
} }
prop_object_release(pkgmetad);
if (access(buf, X_OK) == 0) {
if (xbps_file_exec(xhp, buf, "post",
pkgname, version, update ? "yes" : "no",
xhp->conffile, NULL) != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
errno, pkgname, version,
"%s: [configure] INSTALL script failed to execute "
"the post ACTION: %s", pkgver, strerror(errno));
free(buf);
return errno;
}
} else {
if (errno != ENOENT) {
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
errno, pkgname, version,
"%s: [configure] INSTALL script cannot be "
"executed: %s", pkgver, strerror(errno));
free(buf);
return errno;
}
}
free(buf);
if (state == XBPS_PKG_STATE_INSTALLED) if (state == XBPS_PKG_STATE_INSTALLED)
return rv; return rv;

View File

@ -49,6 +49,7 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
time_t t; time_t t;
struct tm *tmp; struct tm *tmp;
const char *pkgname, *version, *desc, *pkgver; const char *pkgname, *version, *desc, *pkgver;
char *buf, *sha256;
int rv = 0; int rv = 0;
bool autoinst = false; bool autoinst = false;
@ -156,6 +157,15 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
goto out; goto out;
} }
} }
/*
* Create a hash for the pkg's metafile.
*/
buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
sha256 = xbps_file_hash(buf);
assert(sha256);
prop_dictionary_set_cstring(pkgd, "metafile-sha256", sha256);
free(sha256);
free(buf);
/* /*
* Remove unneeded objs from pkg dictionary. * Remove unneeded objs from pkg dictionary.
*/ */

View File

@ -52,7 +52,7 @@
* -# Its state will be changed to XBPS_PKG_STATE_HALF_REMOVED. * -# Its state will be changed to XBPS_PKG_STATE_HALF_REMOVED.
* -# Its <b>purge-remove</b> target specified in the REMOVE script * -# Its <b>purge-remove</b> target specified in the REMOVE script
* will be executed. * will be executed.
* -# Its package metadata directory will be removed. * -# Its package metadata file will be removed.
* -# Package will be unregistered from package database. * -# Package will be unregistered from package database.
* *
* @note * @note
@ -73,50 +73,6 @@
* Text inside of white boxes are the key associated with the object, its * Text inside of white boxes are the key associated with the object, its
* data type is specified on its edge, i.e string, array, integer, dictionary. * data type is specified on its edge, i.e string, array, integer, dictionary.
*/ */
static int
remove_pkg_metadata(struct xbps_handle *xhp,
const char *pkgname,
const char *version,
const char *pkgver)
{
struct dirent *dp;
DIR *dirp;
char *metadir, *path;
int rv = 0;
assert(pkgname != NULL);
metadir = xbps_xasprintf("%s/%s/metadata/%s", xhp->rootdir,
XBPS_META_PATH, pkgname);
dirp = opendir(metadir);
if (dirp == NULL) {
free(metadir);
return errno;
}
while ((dp = readdir(dirp)) != NULL) {
if ((strcmp(dp->d_name, ".") == 0) ||
(strcmp(dp->d_name, "..") == 0))
continue;
path = xbps_xasprintf("%s/%s", metadir, dp->d_name);
if (unlink(path) == -1) {
xbps_set_cb_state(xhp, XBPS_STATE_PURGE_FAIL,
errno, pkgname, version,
"%s: [purge] failed to remove metafile `%s': %s",
pkgver, path, strerror(errno));
}
free(path);
}
(void)closedir(dirp);
rv = rmdir(metadir);
free(metadir);
if (rv != 0)
rv = errno;
return rv;
}
int int
xbps_remove_pkg_files(struct xbps_handle *xhp, xbps_remove_pkg_files(struct xbps_handle *xhp,
prop_dictionary_t dict, prop_dictionary_t dict,
@ -154,6 +110,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
curobj = "directory"; curobj = "directory";
pkgname = xbps_pkg_name(pkgver); pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
version = xbps_pkg_version(pkgver); version = xbps_pkg_version(pkgver);
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
@ -244,8 +201,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
free(path); free(path);
} }
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
if (pkgname) free(pkgname);
free(pkgname);
return rv; return rv;
} }
@ -258,26 +214,22 @@ xbps_remove_pkg(struct xbps_handle *xhp,
bool soft_replace) bool soft_replace)
{ {
prop_dictionary_t pkgd = NULL; prop_dictionary_t pkgd = NULL;
char *tmpname, *buf, *pkgver = NULL; char *tmpname, *buf = NULL, *pkgver = NULL;
const char *tmpver = NULL; const char *tmpver = NULL;
int rv = 0; int rv = 0;
bool rmfile_exists = false;
pkg_state_t state = 0; pkg_state_t state = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
assert(version != NULL); assert(version != NULL);
buf = xbps_xasprintf("%s/metadata/%s/REMOVE",
XBPS_META_PATH, pkgname);
pkgver = xbps_xasprintf("%s-%s", pkgname, version);
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0)
goto out; goto out;
if (!update) if (!update)
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgname, version, NULL); xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgname, version, NULL);
pkgver = xbps_xasprintf("%s-%s", pkgname, version);
if (chdir(xhp->rootdir) == -1) { if (chdir(xhp->rootdir) == -1) {
rv = errno; rv = errno;
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
@ -286,34 +238,24 @@ xbps_remove_pkg(struct xbps_handle *xhp,
pkgver, xhp->rootdir, strerror(rv)); pkgver, xhp->rootdir, strerror(rv));
goto out; goto out;
} }
pkgd = xbps_pkgd_from_metadir(xhp, pkgname);
assert(pkgd);
/* If package was "half-removed", remove it fully. */ /* If package was "half-removed", remove it fully. */
if (state == XBPS_PKG_STATE_HALF_REMOVED) if (state == XBPS_PKG_STATE_HALF_REMOVED)
goto purge; goto purge;
/* /*
* Run the pre remove action. * Run the pre remove action.
*/ */
if (access(buf, X_OK) == 0) { rv = xbps_pkg_exec_script(xhp, pkgd, "remove", "pre", update);
rmfile_exists = true; if (rv != 0) {
if (xbps_file_exec(xhp, buf, "pre", pkgname, version, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
update ? "yes" : "no", xhp->conffile, NULL) != 0) { errno, pkgname, version,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, "%s: [remove] REMOVE script failed to "
errno, pkgname, version, "execute pre ACTION: %s",
"%s: [remove] REMOVE script failed to " pkgver, strerror(errno));
"execute pre ACTION: %s", rv = errno;
pkgver, strerror(errno)); goto out;
rv = errno;
goto out;
}
} else {
if (errno != ENOENT) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
errno, pkgname, version,
"%s: [remove] REMOVE script failed to "
"execute pre ACTION: %s",
pkgver, strerror(errno));
rv = errno;
goto out;
}
} }
/* /*
* If updating a package, we just need to execute the current * If updating a package, we just need to execute the current
@ -322,7 +264,7 @@ xbps_remove_pkg(struct xbps_handle *xhp,
*/ */
if (update) { if (update) {
free(pkgver); free(pkgver);
free(buf); prop_object_release(pkgd);
return xbps_requiredby_pkg_remove(xhp, pkgname); return xbps_requiredby_pkg_remove(xhp, pkgname);
} else if (soft_replace) { } else if (soft_replace) {
/* /*
@ -333,7 +275,6 @@ xbps_remove_pkg(struct xbps_handle *xhp,
goto softreplace; goto softreplace;
} }
pkgd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
if (pkgd) { if (pkgd) {
/* Remove regular files */ /* Remove regular files */
if ((rv = xbps_remove_pkg_files(xhp, pkgd, "files", pkgver)) != 0) if ((rv = xbps_remove_pkg_files(xhp, pkgd, "files", pkgver)) != 0)
@ -352,9 +293,8 @@ xbps_remove_pkg(struct xbps_handle *xhp,
* Execute the post REMOVE action if file exists and we aren't * Execute the post REMOVE action if file exists and we aren't
* updating the package. * updating the package.
*/ */
if (rmfile_exists && rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "post", false);
((rv = xbps_file_exec(xhp, buf, "post", pkgname, version, "no", if (rv != 0) {
xhp->conffile, NULL)) != 0)) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: [remove] REMOVE script failed to execute " "%s: [remove] REMOVE script failed to execute "
@ -390,26 +330,27 @@ purge:
/* /*
* Execute the purge REMOVE action if file exists. * Execute the purge REMOVE action if file exists.
*/ */
if (access(buf, X_OK) == 0) { rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "purge", false);
if ((rv = xbps_file_exec(xhp, buf, "purge", pkgname, version, "no", if (rv != 0) {
xhp->conffile, NULL)) != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: REMOVE script failed to execute " "%s: REMOVE script failed to execute "
"purge ACTION: %s", pkgver, strerror(rv)); "purge ACTION: %s", pkgver, strerror(rv));
goto out; goto out;
}
} }
/* /*
* Remove package metadata directory. * Remove package metadata plist.
*/ */
rv = remove_pkg_metadata(xhp, pkgname, version, pkgver); prop_object_release(pkgd);
if (rv != 0) { pkgd = NULL;
buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
if (remove(buf) == -1) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version, rv, pkgname, version,
"%s: failed to remove metadata files: %s", "%s: failed to remove metadata file: %s",
pkgver, strerror(rv)); pkgver, strerror(errno));
if (rv != ENOENT) if (errno != ENOENT)
goto out; goto out;
} }
/* /*

121
lib/package_script.c Normal file
View File

@ -0,0 +1,121 @@
/*-
* 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 <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "xbps_api_impl.h"
int
xbps_pkg_exec_buffer(struct xbps_handle *xhp,
const void *blob,
const size_t blobsiz,
const char *pkgname,
const char *version,
const char *action,
bool update)
{
ssize_t ret;
const char *tmpdir;
char *fpath;
int fd, rv;
assert(blob);
assert(pkgname);
assert(version);
assert(action);
tmpdir = getenv("TMPDIR");
if (tmpdir == NULL)
tmpdir = P_tmpdir;
fpath = xbps_xasprintf("%s/.xbps-script-XXXXXX", tmpdir);
/* Create temp file to run script */
if ((fd = mkstemp(fpath)) == -1) {
xbps_dbg_printf(xhp, "%s: mkstemp %s\n",
__func__, strerror(errno));
free(fpath);
return errno;
}
/* write blob to our temp fd */
ret = write(fd, blob, blobsiz);
if (ret == -1) {
xbps_dbg_printf(xhp, "%s: write %s\n",
__func__, strerror(errno));
close(fd);
rv = errno;
goto out;
}
fchmod(fd, 0750);
fdatasync(fd);
close(fd);
/* change cwd to rootdir to exec the script */
if (chdir(xhp->rootdir) == -1) {
rv = errno;
goto out;
}
/* exec script */
rv = xbps_file_exec(xhp, fpath, action, pkgname, version,
update ? "yes" : "no",
xhp->conffile, NULL);
out:
remove(fpath);
free(fpath);
return rv;
}
int
xbps_pkg_exec_script(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *script,
const char *action,
bool update)
{
prop_data_t data;
const char *pkgname, *version;
assert(xhp);
assert(d);
assert(script);
assert(action);
data = prop_dictionary_get(d, script);
if (data == NULL)
return 0;
prop_dictionary_get_cstring_nocopy(d, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(d, "version", &version);
return xbps_pkg_exec_buffer(xhp, prop_data_data(data),
prop_data_size(data), pkgname, version,
action, update);
}

View File

@ -48,104 +48,6 @@ set_extract_flags(uid_t euid)
return flags; return flags;
} }
static int
extract_metafile(struct xbps_handle *xhp,
struct archive *ar,
struct archive_entry *entry,
const char *file,
const char *pkgver,
bool exec,
int flags)
{
const char *version;
char *buf, *dirc, *dname, *pkgname;
int rv;
pkgname = xbps_pkg_name(pkgver);
if (pkgname == NULL)
return ENOMEM;
version = xbps_pkg_version(pkgver);
if (version == NULL) {
free(pkgname);
return ENOMEM;
}
buf = xbps_xasprintf("%s/metadata/%s/%s",
XBPS_META_PATH, pkgname, file);
archive_entry_set_pathname(entry, buf);
dirc = strdup(buf);
if (dirc == NULL) {
free(buf);
free(pkgname);
return ENOMEM;
}
free(buf);
dname = dirname(dirc);
if (access(dname, X_OK) == -1) {
if (xbps_mkpath(dname, 0755) == -1) {
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] failed to create metadir `%s': %s",
pkgver, dname, strerror(errno));
free(dirc);
free(pkgname);
return errno;
}
}
if (exec)
archive_entry_set_perm(entry, 0750);
if (archive_read_extract(ar, entry, flags) != 0) {
rv = archive_errno(ar);
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version,
"%s: [unpack] failed to extract metafile `%s': %s",
pkgver, file, strerror(rv));
free(dirc);
free(pkgname);
return rv;
}
free(pkgname);
free(dirc);
return 0;
}
static int
remove_metafile(struct xbps_handle *xhp,
const char *file,
const char *pkgver)
{
const char *version;
char *buf, *pkgname;
pkgname = xbps_pkg_name(pkgver);
if (pkgname == NULL)
return ENOMEM;
version = xbps_pkg_version(pkgver);
if (version == NULL) {
free(pkgname);
return ENOMEM;
}
buf = xbps_xasprintf("%s/metadata/%s/%s",
XBPS_META_PATH, pkgname, file);
if (unlink(buf) == -1) {
if (errno && errno != ENOENT) {
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] failed to remove metafile `%s': %s",
pkgver, file, strerror(errno));
free(pkgname);
free(buf);
return errno;
}
}
free(buf);
free(pkgname);
return 0;
}
static const char * static const char *
find_pkg_symlink_target(prop_dictionary_t d, const char *file) find_pkg_symlink_target(prop_dictionary_t d, const char *file)
{ {
@ -181,14 +83,18 @@ unpack_archive(struct xbps_handle *xhp,
prop_dictionary_t filesd, old_filesd; prop_dictionary_t filesd, old_filesd;
prop_array_t array, obsoletes; prop_array_t array, obsoletes;
prop_object_t obj; prop_object_t obj;
prop_data_t data;
void *instbuf, *rembuf;
const struct stat *entry_statp; const struct stat *entry_statp;
struct stat st; struct stat st;
struct xbps_unpack_cb_data xucd; struct xbps_unpack_cb_data xucd;
struct archive_entry *entry; struct archive_entry *entry;
size_t i, entry_idx = 0; size_t i, entry_idx = 0;
size_t instbufsiz, rembufsiz;
ssize_t entry_size;
const char *file, *entry_pname, *transact, *pkgname; const char *file, *entry_pname, *transact, *pkgname;
const char *version, *pkgver, *fname, *tgtlnk; const char *version, *pkgver, *fname, *tgtlnk;
char *dname, *buf, *buf2, *p, *p2, *pkgfilesd, *pkgpropsd; char *dname, *buf, *buf2, *p, *p2;
int ar_rv, rv, rv_stat, flags; int ar_rv, rv, rv_stat, flags;
bool preserve, update, conf_file, file_exists, skip_obsoletes; bool preserve, update, conf_file, file_exists, skip_obsoletes;
bool softreplace, skip_extract; bool softreplace, skip_extract;
@ -197,8 +103,8 @@ unpack_archive(struct xbps_handle *xhp,
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY); assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
assert(ar != NULL); assert(ar != NULL);
instbuf = rembuf = NULL;
filesd = old_filesd = NULL; filesd = old_filesd = NULL;
pkgfilesd = pkgpropsd = NULL;
preserve = update = conf_file = file_exists = false; preserve = update = conf_file = file_exists = false;
skip_obsoletes = softreplace = false; skip_obsoletes = softreplace = false;
@ -238,15 +144,6 @@ unpack_archive(struct xbps_handle *xhp,
} }
if (strcmp(transact, "update") == 0) if (strcmp(transact, "update") == 0)
update = true; update = true;
/*
* Always remove current INSTALL/REMOVE scripts in pkg's metadir,
* as security measures.
*/
if ((rv = remove_metafile(xhp, "INSTALL", pkgver)) != 0)
goto out;
if ((rv = remove_metafile(xhp, "REMOVE", pkgver)) != 0)
goto out;
/* /*
* Process the archive files. * Process the archive files.
*/ */
@ -259,6 +156,7 @@ unpack_archive(struct xbps_handle *xhp,
entry_statp = archive_entry_stat(entry); entry_statp = archive_entry_stat(entry);
entry_pname = archive_entry_pathname(entry); entry_pname = archive_entry_pathname(entry);
entry_size = archive_entry_size(entry);
flags = set_extract_flags(euid); flags = set_extract_flags(euid);
/* /*
* Ignore directories from archive. * Ignore directories from archive.
@ -273,26 +171,27 @@ unpack_archive(struct xbps_handle *xhp,
if (xhp->unpack_cb != NULL) { if (xhp->unpack_cb != NULL) {
xucd.pkgver = pkgver; xucd.pkgver = pkgver;
xucd.entry = entry_pname; xucd.entry = entry_pname;
xucd.entry_size = archive_entry_size(entry); xucd.entry_size = entry_size;
xucd.entry_is_conf = false; xucd.entry_is_conf = false;
} }
if (strcmp("./INSTALL", entry_pname) == 0) { if (strcmp("./INSTALL", entry_pname) == 0) {
/* /*
* Extract the INSTALL script first to execute * Store file in a buffer and execute
* the pre install target. * the "pre" action from it.
*/ */
buf = xbps_xasprintf("%s/metadata/%s/INSTALL", instbufsiz = entry_size;
XBPS_META_PATH, pkgname); instbuf = malloc(entry_size);
rv = extract_metafile(xhp, ar, entry, assert(instbuf);
"INSTALL", pkgver, true, flags);
if (rv != 0)
goto out;
rv = xbps_file_exec(xhp, buf, "pre", if (archive_read_data(ar, instbuf, entry_size) !=
pkgname, version, update ? "yes" : "no", entry_size) {
xhp->conffile, NULL); rv = EINVAL;
free(buf); free(instbuf);
buf = NULL; goto out;
}
rv = xbps_pkg_exec_buffer(xhp, instbuf, instbufsiz,
pkgname, version, "pre", update);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state(xhp, xbps_set_cb_state(xhp,
XBPS_STATE_UNPACK_FAIL, XBPS_STATE_UNPACK_FAIL,
@ -300,16 +199,22 @@ unpack_archive(struct xbps_handle *xhp,
"%s: [unpack] INSTALL script failed " "%s: [unpack] INSTALL script failed "
"to execute pre ACTION: %s", "to execute pre ACTION: %s",
pkgver, strerror(rv)); pkgver, strerror(rv));
free(instbuf);
goto out; goto out;
} }
continue; continue;
} else if (strcmp("./REMOVE", entry_pname) == 0) { } else if (strcmp("./REMOVE", entry_pname) == 0) {
rv = extract_metafile(xhp, ar, entry, /* store file in a buffer */
"REMOVE", pkgver, true, flags); rembufsiz = entry_size;
if (rv != 0) rembuf = malloc(entry_size);
assert(rembuf);
if (archive_read_data(ar, rembuf, entry_size) !=
entry_size) {
rv = EINVAL;
free(rembuf);
goto out; goto out;
}
continue; continue;
} else if (strcmp("./files.plist", entry_pname) == 0) { } else if (strcmp("./files.plist", entry_pname) == 0) {
@ -571,8 +476,7 @@ unpack_archive(struct xbps_handle *xhp,
* - Package with "preserve" keyword. * - Package with "preserve" keyword.
* - Package with "skip-obsoletes" keyword. * - Package with "skip-obsoletes" keyword.
*/ */
pkgfilesd = xbps_xasprintf("%s/metadata/%s/%s",
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
if (skip_obsoletes || preserve || (!softreplace && !update)) if (skip_obsoletes || preserve || (!softreplace && !update))
goto out1; goto out1;
/* /*
@ -580,7 +484,7 @@ unpack_archive(struct xbps_handle *xhp,
* - Package upgrade. * - Package upgrade.
* - Package with "softreplace" keyword. * - Package with "softreplace" keyword.
*/ */
old_filesd = prop_dictionary_internalize_from_zfile(pkgfilesd); old_filesd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
if (prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY) { if (prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY) {
obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd); obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd);
for (i = 0; i < prop_array_count(obsoletes); i++) { for (i = 0; i < prop_array_count(obsoletes); i++) {
@ -600,60 +504,66 @@ unpack_archive(struct xbps_handle *xhp,
"%s: removed obsolete entry: %s", pkgver, file); "%s: removed obsolete entry: %s", pkgver, file);
prop_object_release(obj); prop_object_release(obj);
} }
prop_object_release(old_filesd);
}
out1:
/*
* Create pkg metadata directory if doesn't exist.
*/
buf = xbps_xasprintf("%s/metadata/%s", XBPS_META_PATH, pkgname);
if (access(buf, R_OK|X_OK) == -1) {
if (xbps_mkpath(buf, 0755) == -1) {
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] failed to create pkg metadir "
"`%s': %s", buf, pkgver, strerror(errno));
free(buf);
rv = errno;
goto out;
}
}
free(buf);
/*
* Externalize XBPS_PKGFILES into pkg's metadir.
*/
if (!prop_dictionary_externalize_to_file(filesd, pkgfilesd)) {
rv = errno;
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] failed to extract metadata file `%s': %s",
pkgver, XBPS_PKGFILES, strerror(errno));
goto out;
} }
out1:
/* Add objects from XBPS_PKGFILES */
array = prop_dictionary_get(filesd, "files");
if (array && prop_array_count(array))
prop_dictionary_set(pkg_repod, "files", array);
array = prop_dictionary_get(filesd, "conf_files");
if (array && prop_array_count(array))
prop_dictionary_set(pkg_repod, "conf_files", array);
array = prop_dictionary_get(filesd, "links");
if (array && prop_array_count(array))
prop_dictionary_set(pkg_repod, "links", array);
array = prop_dictionary_get(filesd, "dirs");
if (array && prop_array_count(array))
prop_dictionary_set(pkg_repod, "dirs", array);
/* Add install/remove scripts data objects */
if (instbuf != NULL) {
data = prop_data_create_data(instbuf, instbufsiz);
assert(data);
prop_dictionary_set(pkg_repod, "install-script", data);
prop_object_release(data);
free(instbuf);
}
if (rembuf != NULL) {
data = prop_data_create_data(rembuf, rembufsiz);
assert(data);
prop_dictionary_set(pkg_repod, "remove-script", data);
prop_object_release(data);
free(rembuf);
}
/* Remove unneeded objs from transaction */ /* Remove unneeded objs from transaction */
prop_dictionary_remove(pkg_repod, "remove-and-update"); prop_dictionary_remove(pkg_repod, "remove-and-update");
prop_dictionary_remove(pkg_repod, "transaction"); prop_dictionary_remove(pkg_repod, "transaction");
prop_dictionary_remove(pkg_repod, "state"); prop_dictionary_remove(pkg_repod, "state");
/* /*
* Externalize XBPS_PKGPROPS into pkg's metadir. * Externalize pkg dictionary to metadir.
*/ */
pkgpropsd = xbps_xasprintf("%s/metadata/%s/%s", if (access(xhp->metadir, R_OK|X_OK) == -1) {
XBPS_META_PATH, pkgname, XBPS_PKGPROPS); if (errno == ENOENT) {
if (!prop_dictionary_externalize_to_file(pkg_repod, pkgpropsd)) { xbps_mkpath(xhp->metadir, 0755);
} else {
rv = errno;
goto out;
}
}
buf = xbps_xasprintf("%s/.%s.plist", XBPS_META_PATH, pkgname);
if (!prop_dictionary_externalize_to_file(pkg_repod, buf)) {
rv = errno; rv = errno;
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: [unpack] failed to extract metadata file `%s': %s", "%s: [unpack] failed to extract metadata file `%s': %s",
pkgver, XBPS_PKGPROPS, strerror(errno)); pkgver, buf, strerror(errno));
free(buf);
goto out; goto out;
} }
free(buf);
out: out:
if (pkgfilesd != NULL)
free(pkgfilesd);
if (pkgpropsd != NULL)
free(pkgpropsd);
if (prop_object_type(filesd) == PROP_TYPE_DICTIONARY) if (prop_object_type(filesd) == PROP_TYPE_DICTIONARY)
prop_object_release(filesd); prop_object_release(filesd);

View File

@ -266,32 +266,28 @@ xbps_array_replace_dict_by_pattern(prop_array_t array,
} }
prop_dictionary_t prop_dictionary_t
xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp, xbps_pkgd_from_metadir(struct xbps_handle *xhp, const char *name)
const char *pkgname,
const char *plist)
{ {
prop_dictionary_t pkgd, plistd = NULL; prop_dictionary_t pkgd, plistd = NULL;
const char *savedpkgname; const char *savedpkgname;
char *plistf; char *plistf;
assert(pkgname != NULL); assert(name != NULL);
assert(plist != NULL);
savedpkgname = pkgname; savedpkgname = name;
plistf = xbps_xasprintf("%s/metadata/%s/%s", xhp->metadir, plistf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, name);
savedpkgname, plist);
if (access(plistf, R_OK) == -1) { if (access(plistf, R_OK) == -1) {
pkgd = xbps_find_virtualpkg_dict_installed(xhp, pkgname, false); pkgd = xbps_find_virtualpkg_dict_installed(xhp, name, false);
if (pkgd == NULL) if (pkgd == NULL)
pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false); pkgd = xbps_find_pkg_dict_installed(xhp, name, false);
if (pkgd != NULL) { if (pkgd != NULL) {
free(plistf); free(plistf);
prop_dictionary_get_cstring_nocopy(pkgd, prop_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &savedpkgname); "pkgname", &savedpkgname);
plistf = xbps_xasprintf("%s/metadata/%s/%s", plistf = xbps_xasprintf("%s/.%s.plist",
xhp->metadir, savedpkgname, plist); xhp->metadir, savedpkgname);
} }
} }
@ -299,7 +295,7 @@ xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
free(plistf); free(plistf);
if (plistd == NULL) { if (plistd == NULL) {
xbps_dbg_printf(xhp, "cannot read from metadata %s for %s: %s\n", xbps_dbg_printf(xhp, "cannot read from metadata %s for %s: %s\n",
plist, savedpkgname, strerror(errno)); plistf, savedpkgname, strerror(errno));
return NULL; return NULL;
} }

View File

@ -69,15 +69,15 @@ xbps_rpool_init(struct xbps_handle *xhp)
rv = errno; rv = errno;
goto out; goto out;
} }
array = prop_array_internalize_from_zfile(plist); if (access(plist, R_OK) == -1) {
free(plist); xbps_dbg_printf(xhp, "[rpool] `%s' cannot be "
if (array == NULL) { "internalized: %s\n", repouri, strerror(errno));
xbps_dbg_printf(xhp,
"[rpool] `%s' cannot be internalized:"
" %s\n", repouri, strerror(errno));
nmissing++; nmissing++;
continue; continue;
} }
array = prop_array_internalize_from_zfile(plist);
free(plist);
assert(array);
/* /*
* Register repository into the array. * Register repository into the array.
*/ */

View File

@ -84,7 +84,7 @@ check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
rv = EINVAL; rv = EINVAL;
break; break;
} }
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgname, version, xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgver, filen,
"Verifying `%s' package integrity...", filen, repoloc); "Verifying `%s' package integrity...", filen, repoloc);
rv = xbps_file_hash_check(binfile, sha256); rv = xbps_file_hash_check(binfile, sha256);
if (rv != 0) { if (rv != 0) {
@ -110,6 +110,7 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
const char *pkgname, *version, *fetchstr; const char *pkgname, *version, *fetchstr;
char *binfile; char *binfile;
int rv = 0; int rv = 0;
bool state_dload = false;
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "transaction", &trans); prop_dictionary_get_cstring_nocopy(obj, "transaction", &trans);
@ -150,6 +151,11 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
break; break;
} }
} }
if (state_dload == false) {
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_DOWNLOAD,
0, NULL, NULL, NULL);
state_dload = true;
}
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD, xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD,
0, pkgname, version, 0, pkgname, version,
"Downloading binary package `%s' (from `%s')...", "Downloading binary package `%s' (from `%s')...",
@ -207,7 +213,6 @@ xbps_transaction_commit(struct xbps_handle *xhp)
/* /*
* Download binary packages (if they come from a remote repository). * Download binary packages (if they come from a remote repository).
*/ */
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, NULL);
if ((rv = download_binpkgs(xhp, iter)) != 0) if ((rv = download_binpkgs(xhp, iter)) != 0)
goto out; goto out;
/* /*

View File

@ -97,9 +97,7 @@ compute_transaction_stats(struct xbps_handle *xhp)
*/ */
if ((strcmp(tract, "remove") == 0) || if ((strcmp(tract, "remove") == 0) ||
(strcmp(tract, "update") == 0)) { (strcmp(tract, "update") == 0)) {
pkg_metad = pkg_metad = xbps_pkgd_from_metadir(xhp, pkgname);
xbps_dictionary_from_metadata_plist(xhp,
pkgname, XBPS_PKGPROPS);
if (pkg_metad == NULL) if (pkg_metad == NULL)
continue; continue;
prop_dictionary_get_uint64(pkg_metad, prop_dictionary_get_uint64(pkg_metad,

View File

@ -41,7 +41,7 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
const char *pattern, *pkgname, *curpkgname, *pkgver, *curpkgver; const char *pattern, *pkgname, *curpkgname, *pkgver, *curpkgver;
char *dirc, *buf, *dname; char *buf;
bool instd_auto, sr; bool instd_auto, sr;
size_t idx; size_t idx;
@ -160,35 +160,21 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
"automatic-install", instd_auto); "automatic-install", instd_auto);
prop_dictionary_set_bool(instd, prop_dictionary_set_bool(instd,
"softreplace", true); "softreplace", true);
buf = xbps_xasprintf("%s/%s/metadata/%s/%s", buf = xbps_xasprintf("%s/.%s.plist",
xhp->rootdir, XBPS_META_PATH, curpkgname, xhp->metadir, curpkgname);
XBPS_PKGFILES);
filesd = prop_dictionary_internalize_from_zfile(buf); filesd = prop_dictionary_internalize_from_zfile(buf);
free(buf); free(buf);
assert(filesd != NULL); assert(filesd != NULL);
buf = xbps_xasprintf("%s/%s/metadata/%s/%s", buf = xbps_xasprintf("%s/.%s.plist",
xhp->rootdir, XBPS_META_PATH, pkgname, xhp->metadir, pkgname);
XBPS_PKGFILES);
dirc = strdup(buf);
assert(dirc != NULL);
dname = dirname(dirc);
if (xbps_mkpath(dname, 0755) == -1) {
if (errno != EEXIST) {
free(buf);
prop_object_iterator_release(iter);
return errno;
}
}
if (!prop_dictionary_externalize_to_zfile(filesd, buf)) { if (!prop_dictionary_externalize_to_zfile(filesd, buf)) {
free(buf); free(buf);
free(dirc);
prop_object_release(filesd); prop_object_release(filesd);
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
return errno; return errno;
} }
prop_object_release(filesd); prop_object_release(filesd);
free(buf); free(buf);
free(dirc);
} }
/* /*
* Add package dictionary into the transaction and mark * Add package dictionary into the transaction and mark