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 (???):
* 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
PackagesOnHold configuration option.

View File

@ -510,9 +510,9 @@ main(int argc, char **argv)
/*
* 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)
die("cannot internalize %s from %s", XBPS_PKGPROPS, argv[0]);
die("cannot internalize %s metadata file", argv[0]);
/*
* Create the output FILE.

View File

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

View File

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

View File

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

View File

@ -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)

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
* 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
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) \
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_ */

View File

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

View File

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

View File

@ -56,7 +56,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20121111-1"
#define XBPS_API_VERSION "20121116"
#ifndef XBPS_VERSION
#define XBPS_VERSION "UNSET"
@ -1204,19 +1204,51 @@ prop_object_iterator_t xbps_array_iter_from_dict(prop_dictionary_t dict,
const char *key);
/**
* Returns a proplib object dictionary associated with the installed package
* \a pkgname, by internalizing its plist file defined in \a plist.
* Returns a proplib dictionary associated with the installed package
* \a name, by internalizing its plist file from metadir.
*
* @param[in] xhp The pointer to the xbps_handle struct.
* @param[in] pkgname Package name of installed package.
* @param[in] plist Package metadata property list file.
* @param[in] name Package name of installed package.
*
* @return The proplib object dictionary on success, NULL otherwise and
* @return The proplib dictionary on success, NULL otherwise and
* errno is set appropiately.
*/
prop_dictionary_t xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
const char *pkgname,
const char *plist);
prop_dictionary_t xbps_pkgd_from_metadir(struct xbps_handle *xhp,
const char *name);
/**
* 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

View File

@ -44,6 +44,7 @@ EXTOBJS += external/mkpath.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_unpack.o package_requiredby.o package_register.o
OBJS += package_script.o
OBJS += transaction_commit.o transaction_package_replace.o
OBJS += transaction_dictionary.o transaction_sortdeps.o transaction_ops.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",
pkgname, version, entry_pname);
forigd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
forigd = xbps_pkgd_from_metadir(xhp, pkgname);
if (forigd == NULL) {
xbps_dbg_printf(xhp, "%s-%s: conf_file %s not currently "
"installed\n", pkgname, version, entry_pname);
rv = 1;
prop_object_release(forigd);
goto out;
}

View File

@ -77,9 +77,8 @@ xbps_configure_pkg(struct xbps_handle *xhp,
bool update,
bool flush)
{
prop_dictionary_t pkgd;
prop_dictionary_t pkgd, pkgmetad;
const char *version, *pkgver;
char *buf;
int rv = 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);
buf = xbps_xasprintf("%s/metadata/%s/INSTALL",
XBPS_META_PATH, pkgname);
if (chdir(xhp->rootdir) == -1) {
pkgmetad = xbps_pkgd_from_metadir(xhp, pkgname);
assert(pkgmetad);
rv = xbps_pkg_exec_script(xhp, pkgmetad, "install-script", "post", update);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
errno, pkgname, version,
"%s: [configure] failed to chdir to rootdir `%s': %s",
pkgver, xhp->rootdir, strerror(errno));
free(buf);
return EINVAL;
"%s: [configure] INSTALL script failed to execute "
"the post ACTION: %s", pkgver, strerror(rv));
prop_object_release(pkgmetad);
return rv;
}
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);
prop_object_release(pkgmetad);
if (state == XBPS_PKG_STATE_INSTALLED)
return rv;

View File

@ -49,6 +49,7 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
time_t t;
struct tm *tmp;
const char *pkgname, *version, *desc, *pkgver;
char *buf, *sha256;
int rv = 0;
bool autoinst = false;
@ -156,6 +157,15 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
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.
*/

View File

@ -52,7 +52,7 @@
* -# Its state will be changed to XBPS_PKG_STATE_HALF_REMOVED.
* -# Its <b>purge-remove</b> target specified in the REMOVE script
* will be executed.
* -# Its package metadata directory will be removed.
* -# Its package metadata file will be removed.
* -# Package will be unregistered from package database.
*
* @note
@ -73,50 +73,6 @@
* 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.
*/
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
xbps_remove_pkg_files(struct xbps_handle *xhp,
prop_dictionary_t dict,
@ -154,6 +110,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
curobj = "directory";
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
version = xbps_pkg_version(pkgver);
while ((obj = prop_object_iterator_next(iter))) {
@ -244,8 +201,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
free(path);
}
prop_object_iterator_release(iter);
if (pkgname)
free(pkgname);
free(pkgname);
return rv;
}
@ -258,26 +214,22 @@ xbps_remove_pkg(struct xbps_handle *xhp,
bool soft_replace)
{
prop_dictionary_t pkgd = NULL;
char *tmpname, *buf, *pkgver = NULL;
char *tmpname, *buf = NULL, *pkgver = NULL;
const char *tmpver = NULL;
int rv = 0;
bool rmfile_exists = false;
pkg_state_t state = 0;
assert(pkgname != 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)
goto out;
if (!update)
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgname, version, NULL);
pkgver = xbps_xasprintf("%s-%s", pkgname, version);
if (chdir(xhp->rootdir) == -1) {
rv = errno;
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));
goto out;
}
pkgd = xbps_pkgd_from_metadir(xhp, pkgname);
assert(pkgd);
/* If package was "half-removed", remove it fully. */
if (state == XBPS_PKG_STATE_HALF_REMOVED)
goto purge;
/*
* Run the pre remove action.
*/
if (access(buf, X_OK) == 0) {
rmfile_exists = true;
if (xbps_file_exec(xhp, buf, "pre", pkgname, version,
update ? "yes" : "no", xhp->conffile, NULL) != 0) {
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;
}
} 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;
}
rv = xbps_pkg_exec_script(xhp, pkgd, "remove", "pre", update);
if (rv != 0) {
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
@ -322,7 +264,7 @@ xbps_remove_pkg(struct xbps_handle *xhp,
*/
if (update) {
free(pkgver);
free(buf);
prop_object_release(pkgd);
return xbps_requiredby_pkg_remove(xhp, pkgname);
} else if (soft_replace) {
/*
@ -333,7 +275,6 @@ xbps_remove_pkg(struct xbps_handle *xhp,
goto softreplace;
}
pkgd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
if (pkgd) {
/* Remove regular files */
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
* updating the package.
*/
if (rmfile_exists &&
((rv = xbps_file_exec(xhp, buf, "post", pkgname, version, "no",
xhp->conffile, NULL)) != 0)) {
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "post", false);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version,
"%s: [remove] REMOVE script failed to execute "
@ -390,26 +330,27 @@ purge:
/*
* Execute the purge REMOVE action if file exists.
*/
if (access(buf, X_OK) == 0) {
if ((rv = xbps_file_exec(xhp, buf, "purge", pkgname, version, "no",
xhp->conffile, NULL)) != 0) {
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "purge", false);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version,
"%s: REMOVE script failed to execute "
"purge ACTION: %s", pkgver, strerror(rv));
goto out;
}
}
/*
* Remove package metadata directory.
* Remove package metadata plist.
*/
rv = remove_pkg_metadata(xhp, pkgname, version, pkgver);
if (rv != 0) {
prop_object_release(pkgd);
pkgd = NULL;
buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
if (remove(buf) == -1) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version,
"%s: failed to remove metadata files: %s",
pkgver, strerror(rv));
if (rv != ENOENT)
"%s: failed to remove metadata file: %s",
pkgver, strerror(errno));
if (errno != ENOENT)
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;
}
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 *
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_array_t array, obsoletes;
prop_object_t obj;
prop_data_t data;
void *instbuf, *rembuf;
const struct stat *entry_statp;
struct stat st;
struct xbps_unpack_cb_data xucd;
struct archive_entry *entry;
size_t i, entry_idx = 0;
size_t instbufsiz, rembufsiz;
ssize_t entry_size;
const char *file, *entry_pname, *transact, *pkgname;
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;
bool preserve, update, conf_file, file_exists, skip_obsoletes;
bool softreplace, skip_extract;
@ -197,8 +103,8 @@ unpack_archive(struct xbps_handle *xhp,
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
assert(ar != NULL);
instbuf = rembuf = NULL;
filesd = old_filesd = NULL;
pkgfilesd = pkgpropsd = NULL;
preserve = update = conf_file = file_exists = false;
skip_obsoletes = softreplace = false;
@ -238,15 +144,6 @@ unpack_archive(struct xbps_handle *xhp,
}
if (strcmp(transact, "update") == 0)
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.
*/
@ -259,6 +156,7 @@ unpack_archive(struct xbps_handle *xhp,
entry_statp = archive_entry_stat(entry);
entry_pname = archive_entry_pathname(entry);
entry_size = archive_entry_size(entry);
flags = set_extract_flags(euid);
/*
* Ignore directories from archive.
@ -273,26 +171,27 @@ unpack_archive(struct xbps_handle *xhp,
if (xhp->unpack_cb != NULL) {
xucd.pkgver = pkgver;
xucd.entry = entry_pname;
xucd.entry_size = archive_entry_size(entry);
xucd.entry_size = entry_size;
xucd.entry_is_conf = false;
}
if (strcmp("./INSTALL", entry_pname) == 0) {
/*
* Extract the INSTALL script first to execute
* the pre install target.
* Store file in a buffer and execute
* the "pre" action from it.
*/
buf = xbps_xasprintf("%s/metadata/%s/INSTALL",
XBPS_META_PATH, pkgname);
rv = extract_metafile(xhp, ar, entry,
"INSTALL", pkgver, true, flags);
if (rv != 0)
goto out;
instbufsiz = entry_size;
instbuf = malloc(entry_size);
assert(instbuf);
rv = xbps_file_exec(xhp, buf, "pre",
pkgname, version, update ? "yes" : "no",
xhp->conffile, NULL);
free(buf);
buf = NULL;
if (archive_read_data(ar, instbuf, entry_size) !=
entry_size) {
rv = EINVAL;
free(instbuf);
goto out;
}
rv = xbps_pkg_exec_buffer(xhp, instbuf, instbufsiz,
pkgname, version, "pre", update);
if (rv != 0) {
xbps_set_cb_state(xhp,
XBPS_STATE_UNPACK_FAIL,
@ -300,16 +199,22 @@ unpack_archive(struct xbps_handle *xhp,
"%s: [unpack] INSTALL script failed "
"to execute pre ACTION: %s",
pkgver, strerror(rv));
free(instbuf);
goto out;
}
continue;
} else if (strcmp("./REMOVE", entry_pname) == 0) {
rv = extract_metafile(xhp, ar, entry,
"REMOVE", pkgver, true, flags);
if (rv != 0)
/* store file in a buffer */
rembufsiz = entry_size;
rembuf = malloc(entry_size);
assert(rembuf);
if (archive_read_data(ar, rembuf, entry_size) !=
entry_size) {
rv = EINVAL;
free(rembuf);
goto out;
}
continue;
} else if (strcmp("./files.plist", entry_pname) == 0) {
@ -571,8 +476,7 @@ unpack_archive(struct xbps_handle *xhp,
* - Package with "preserve" 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))
goto out1;
/*
@ -580,7 +484,7 @@ unpack_archive(struct xbps_handle *xhp,
* - Package upgrade.
* - 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) {
obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd);
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);
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 */
prop_dictionary_remove(pkg_repod, "remove-and-update");
prop_dictionary_remove(pkg_repod, "transaction");
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",
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
if (!prop_dictionary_externalize_to_file(pkg_repod, pkgpropsd)) {
if (access(xhp->metadir, R_OK|X_OK) == -1) {
if (errno == ENOENT) {
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;
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] failed to extract metadata file `%s': %s",
pkgver, XBPS_PKGPROPS, strerror(errno));
pkgver, buf, strerror(errno));
free(buf);
goto out;
}
free(buf);
out:
if (pkgfilesd != NULL)
free(pkgfilesd);
if (pkgpropsd != NULL)
free(pkgpropsd);
if (prop_object_type(filesd) == PROP_TYPE_DICTIONARY)
prop_object_release(filesd);

View File

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

View File

@ -69,15 +69,15 @@ xbps_rpool_init(struct xbps_handle *xhp)
rv = errno;
goto out;
}
array = prop_array_internalize_from_zfile(plist);
free(plist);
if (array == NULL) {
xbps_dbg_printf(xhp,
"[rpool] `%s' cannot be internalized:"
" %s\n", repouri, strerror(errno));
if (access(plist, R_OK) == -1) {
xbps_dbg_printf(xhp, "[rpool] `%s' cannot be "
"internalized: %s\n", repouri, strerror(errno));
nmissing++;
continue;
}
array = prop_array_internalize_from_zfile(plist);
free(plist);
assert(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;
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);
rv = xbps_file_hash_check(binfile, sha256);
if (rv != 0) {
@ -110,6 +110,7 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
const char *pkgname, *version, *fetchstr;
char *binfile;
int rv = 0;
bool state_dload = false;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "transaction", &trans);
@ -150,6 +151,11 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
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,
0, pkgname, version,
"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).
*/
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, NULL);
if ((rv = download_binpkgs(xhp, iter)) != 0)
goto out;
/*

View File

@ -97,9 +97,7 @@ compute_transaction_stats(struct xbps_handle *xhp)
*/
if ((strcmp(tract, "remove") == 0) ||
(strcmp(tract, "update") == 0)) {
pkg_metad =
xbps_dictionary_from_metadata_plist(xhp,
pkgname, XBPS_PKGPROPS);
pkg_metad = xbps_pkgd_from_metadir(xhp, pkgname);
if (pkg_metad == NULL)
continue;
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_iterator_t iter;
const char *pattern, *pkgname, *curpkgname, *pkgver, *curpkgver;
char *dirc, *buf, *dname;
char *buf;
bool instd_auto, sr;
size_t idx;
@ -160,35 +160,21 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
"automatic-install", instd_auto);
prop_dictionary_set_bool(instd,
"softreplace", true);
buf = xbps_xasprintf("%s/%s/metadata/%s/%s",
xhp->rootdir, XBPS_META_PATH, curpkgname,
XBPS_PKGFILES);
buf = xbps_xasprintf("%s/.%s.plist",
xhp->metadir, curpkgname);
filesd = prop_dictionary_internalize_from_zfile(buf);
free(buf);
assert(filesd != NULL);
buf = xbps_xasprintf("%s/%s/metadata/%s/%s",
xhp->rootdir, XBPS_META_PATH, 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;
}
}
buf = xbps_xasprintf("%s/.%s.plist",
xhp->metadir, pkgname);
if (!prop_dictionary_externalize_to_zfile(filesd, buf)) {
free(buf);
free(dirc);
prop_object_release(filesd);
prop_object_iterator_release(iter);
return errno;
}
prop_object_release(filesd);
free(buf);
free(dirc);
}
/*
* Add package dictionary into the transaction and mark