Misc cleanups and performance improvements.

- There's no need to check rval for prop_dictionary_get_*, we are sure the
  objects are there at prop_dictionary_set_* time.
- Avoid two chdir(2) calls per INSTALL/REMOVE run.
- Avoid using access(2) to check for existence of INSTALL/REMOVE scripts,
  just try to run the executable directly and check for ENOENT.
This commit is contained in:
Juan RP 2010-11-06 06:44:00 +01:00
parent f8629652da
commit ec7cdde1e0
22 changed files with 228 additions and 461 deletions

View File

@ -66,18 +66,8 @@ xbps_check_pkg_integrity_all(void)
}
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
prop_object_iterator_release(iter);
rv = errno;
goto out;
}
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version)) {
prop_object_iterator_release(iter);
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
printf("Checking %s-%s ...\n", pkgname, version);
if ((rv = xbps_check_pkg_integrity(pkgname)) != 0)
nbrokenpkgs++;
@ -192,12 +182,7 @@ xbps_check_pkg_integrity(const char *pkgname)
goto out;
}
while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &file)) {
prop_object_iterator_release(iter);
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
path = xbps_xasprintf("%s/%s",
xbps_get_rootdir(), file);
if (path == NULL) {
@ -205,13 +190,8 @@ xbps_check_pkg_integrity(const char *pkgname)
rv = errno;
goto out;
}
if (!prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256)) {
free(path);
prop_object_iterator_release(iter);
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256);
rv = xbps_check_file_hash(path, sha256);
switch (rv) {
case 0:
@ -253,12 +233,7 @@ xbps_check_pkg_integrity(const char *pkgname)
goto out;
}
while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &file)) {
prop_object_iterator_release(iter);
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
path = xbps_xasprintf("%s/%s",
xbps_get_rootdir(), file);
if (path == NULL) {

View File

@ -105,18 +105,11 @@ download_package_list(prop_object_iterator_t iter)
xbps_fetch_set_cache_connection(0, 0);
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"repository", &repoloc))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"filename", &filename))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"filename-sha256", &sha256))
return errno;
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
prop_dictionary_get_cstring_nocopy(obj,
"filename-sha256", &sha256);
lbinfile = xbps_get_binpkg_local_path(obj, repoloc);
if (lbinfile == NULL)
@ -196,12 +189,8 @@ show_package_list(prop_object_iterator_t iter, const char *match)
bool first = false;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver))
return;
if (!prop_dictionary_get_cstring_nocopy(obj,
"trans-action", &tract))
return;
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
if (strcmp(match, tract))
continue;
@ -232,10 +221,7 @@ show_transaction_sizes(struct transaction *trans)
trans_inst = trans_up = trans_conf = false;
while ((obj = prop_object_iterator_next(trans->iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"trans-action", &tract))
return errno;
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
if (strcmp(tract, "install") == 0) {
trans->inst_pkgcnt++;
trans_inst = true;
@ -271,12 +257,9 @@ show_transaction_sizes(struct transaction *trans)
/*
* Show total download/installed size for all required packages.
*/
if (!prop_dictionary_get_uint64(trans->dict,
"total-download-size", &dlsize))
return errno;
if (!prop_dictionary_get_uint64(trans->dict,
"total-installed-size", &instsize))
return errno;
prop_dictionary_get_uint64(trans->dict, "total-download-size", &dlsize);
prop_dictionary_get_uint64(trans->dict, "total-installed-size",
&instsize);
if (xbps_humanize_number(size, 5, (int64_t)dlsize,
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE) == -1) {
fprintf(stderr, "xbps-bin: error: humanize_number returns "
@ -509,21 +492,17 @@ exec_transaction(struct transaction *trans)
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
autoinst = preserve = false;
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"filename", &filename))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"trans-action", &tract))
return errno;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
assert(pkgname != NULL);
assert(version != NULL);
assert(pkgver != NULL);
assert(filename != NULL);
assert(tract != NULL);
prop_dictionary_get_bool(obj, "automatic-install", &autoinst);
prop_dictionary_get_bool(obj, "preserve", &preserve);
@ -561,11 +540,8 @@ exec_transaction(struct transaction *trans)
return EINVAL;
}
if (!prop_dictionary_get_cstring_nocopy(instpkgd,
"version", &instver)) {
prop_object_release(instpkgd);
return errno;
}
prop_dictionary_get_cstring_nocopy(instpkgd,
"version", &instver);
prop_object_release(instpkgd);
if (preserve)
@ -607,15 +583,9 @@ exec_transaction(struct transaction *trans)
*/
printf("\n[3/3] Configuring\n");
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"trans-action", &tract))
return errno;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
update = false;
if (strcmp(tract, "update") == 0)
update = true;

View File

@ -38,8 +38,7 @@ pkg_remove_and_purge(const char *pkgname, const char *version, bool purge)
{
int rv = 0;
printf("Removing package %s-%s ... ", pkgname, version);
(void)fflush(stdout);
printf("Removing package %s-%s ...\n", pkgname, version);
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0) {
fprintf(stderr, "\nE: unable to remove %s-%s (%s).\n",
@ -47,7 +46,7 @@ pkg_remove_and_purge(const char *pkgname, const char *version, bool purge)
return rv;
}
if (purge) {
printf("purging ... ");
printf(" Purging ... ");
(void)fflush(stdout);
if ((rv = xbps_purge_pkg(pkgname, false)) != 0) {
fprintf(stderr, "\nE: unable to purge %s-%s "
@ -55,8 +54,8 @@ pkg_remove_and_purge(const char *pkgname, const char *version, bool purge)
strerror(errno));
return rv;
}
printf("done.\n");
}
printf("done.\n");
return rv;
}
@ -95,11 +94,7 @@ xbps_autoremove_pkgs(bool force, bool purge, bool only_show)
printf("The following packages were installed automatically\n"
"(as dependencies) and aren't needed anymore:\n\n");
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver)) {
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
cols += strlen(pkgver) + 4;
if (cols <= 80) {
if (first == false) {
@ -124,16 +119,8 @@ xbps_autoremove_pkgs(bool force, bool purge, bool only_show)
}
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
rv = errno;
goto out;
}
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version)) {
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
if ((rv = pkg_remove_and_purge(pkgname, version, purge)) != 0)
goto out;
}
@ -166,10 +153,7 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool force, bool purge)
printf("Package %s is not installed.\n", argv[i]);
continue;
}
if (!prop_dictionary_get_cstring_nocopy(dict, "version",
&version))
return errno;
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
found = true;
reqby = prop_dictionary_get(dict, "requiredby");
if (reqby != NULL && prop_array_count(reqby) > 0) {

View File

@ -111,16 +111,8 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *filedir,
"file, skipping!\n", file, XBPS_PKGPROPS);
goto out;
}
if (!prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname", &pkgname)) {
prop_object_release(newpkgd);
rv = errno;
goto out;
}
if (!prop_dictionary_get_cstring_nocopy(newpkgd, "version", &version)) {
prop_object_release(newpkgd);
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(newpkgd, "version", &version);
/*
* Check if this package exists already in the index, but first
* checking the version. If current package version is greater
@ -135,12 +127,7 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *filedir,
goto out;
}
} else if (curpkgd) {
if (!prop_dictionary_get_cstring_nocopy(curpkgd,
"version", &regver)) {
prop_object_release(newpkgd);
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(curpkgd, "version", &regver);
if (xbps_cmpver(version, regver) <= 0) {
fprintf(stderr, "W: skipping %s. %s-%s already "
"registered.\n", filen, pkgname, regver);
@ -153,12 +140,8 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *filedir,
* in package index, remove outdated binpkg file
* and its dictionary from the pkg index.
*/
if (!prop_dictionary_get_cstring_nocopy(curpkgd,
"filename", &oldfilen)) {
prop_object_release(newpkgd);
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(curpkgd,
"filename", &oldfilen);
oldfilepath = xbps_xasprintf("%s/%s", filedir, oldfilen);
if (oldfilepath == NULL) {
prop_object_release(newpkgd);

View File

@ -292,11 +292,7 @@ show_pkg_deps_from_repolist(const char *pkgname)
}
continue;
}
if (!prop_dictionary_get_cstring_nocopy(pkgd,
"version", &ver)) {
rv = errno;
break;
}
prop_dictionary_get_cstring_nocopy(pkgd, "version", &ver);
printf("Repository %s [pkgver: %s]\n", rd->rp_uri, ver);
(void)xbps_callback_array_iter_in_dict(pkgd,
"run_depends", list_strings_sep_in_array, NULL);

View File

@ -164,11 +164,7 @@ show_pkg_files(prop_dictionary_t filesd)
return EINVAL;
while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &file)) {
prop_object_iterator_release(iter);
return errno;
}
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
printf("%s\n", file);
}
prop_object_iterator_release(iter);

View File

@ -209,10 +209,7 @@ main(int argc, char **argv)
if (dict == NULL)
exit(EXIT_FAILURE);
if (!prop_dictionary_get_cstring_nocopy(dict, "version",
&version))
exit(EXIT_FAILURE);
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
printf("%s\n", version);
prop_object_release(dict);

View File

@ -73,12 +73,8 @@ xbps_config_file_from_archive_entry(prop_dictionary_t d,
iter2 = xbps_get_array_iter_from_dict(forigd, "conf_files");
if (iter2 != NULL) {
while ((obj2 = prop_object_iterator_next(iter2))) {
if (!prop_dictionary_get_cstring_nocopy(obj2,
"file", &cffile)) {
prop_object_iterator_release(iter2);
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(obj2,
"file", &cffile);
buf = xbps_xasprintf(".%s", cffile);
if (buf == NULL) {
prop_object_iterator_release(iter2);
@ -109,11 +105,7 @@ xbps_config_file_from_archive_entry(prop_dictionary_t d,
* Compare original, installed and new hash for current file.
*/
while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &cffile)) {
prop_object_iterator_release(iter);
return errno;
}
prop_dictionary_get_cstring_nocopy(obj, "file", &cffile);
buf = xbps_xasprintf(".%s", cffile);
if (buf == NULL) {
prop_object_iterator_release(iter);
@ -126,11 +118,7 @@ xbps_config_file_from_archive_entry(prop_dictionary_t d,
}
sha256_cur = xbps_get_file_hash(buf);
free(buf);
if (!prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256_new)) {
rv = EINVAL;
break;
}
prop_dictionary_get_cstring_nocopy(obj, "sha256", &sha256_new);
if (sha256_cur == NULL) {
if (errno == ENOENT) {
/*

View File

@ -54,7 +54,6 @@ xbps_configure_all_pkgs(void)
prop_object_iterator_t iter;
const char *pkgname, *version;
int rv = 0;
pkg_state_t state = 0;
if ((d = xbps_regpkgs_dictionary_init()) == NULL)
return errno;
@ -66,22 +65,10 @@ xbps_configure_all_pkgs(void)
}
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
rv = errno;
break;
}
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version)) {
rv = errno;
break;
}
if ((rv = xbps_get_pkg_state_dictionary(obj, &state)) != 0)
break;
if (state != XBPS_PKG_STATE_UNPACKED)
continue;
if ((rv = xbps_configure_pkg(pkgname, version,
false, false)) != 0)
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
rv = xbps_configure_pkg(pkgname, version, true, false);
if (rv != 0)
break;
}
prop_object_iterator_release(iter);
@ -96,7 +83,7 @@ xbps_configure_pkg(const char *pkgname, const char *version, bool check_state,
bool update)
{
prop_dictionary_t pkgd;
const char *rootdir, *lver;
const char *lver, *rootdir = xbps_get_rootdir();
char *buf;
int rv = 0, flags = 0;
pkg_state_t state = 0;
@ -104,7 +91,6 @@ xbps_configure_pkg(const char *pkgname, const char *version, bool check_state,
assert(pkgname != NULL);
rootdir = xbps_get_rootdir();
flags = xbps_get_flags();
if (check_state) {
@ -123,11 +109,7 @@ xbps_configure_pkg(const char *pkgname, const char *version, bool check_state,
if (pkgd == NULL)
return errno;
if (!prop_dictionary_get_cstring_nocopy(pkgd,
"version", &lver)) {
prop_object_release(pkgd);
return errno;
}
prop_dictionary_get_cstring_nocopy(pkgd, "version", &lver);
prop_object_release(pkgd);
} else {
lver = version;
@ -141,28 +123,18 @@ xbps_configure_pkg(const char *pkgname, const char *version, bool check_state,
if (buf == NULL)
return errno;
if (strcmp(rootdir, "") == 0)
rootdir = "/";
if (chdir(rootdir) == -1) {
free(buf);
return errno;
}
if (access(buf, X_OK) == 0) {
rv = xbps_file_chdir_exec(rootdir, buf, "post",
pkgname, lver, update ? "yes" : "no", NULL);
if (rv != 0) {
free(buf);
fprintf(stderr, "%s: post INSTALL action "
"returned: %s\n", pkgname, strerror(errno));
return rv;
}
} else {
if (errno != ENOENT) {
free(buf);
return errno;
}
rv = xbps_file_exec(buf, "post",
pkgname, lver, update ? "yes" : "no", NULL);
if (rv != 0 && errno != ENOENT) {
free(buf);
fprintf(stderr, "%s: post INSTALL action "
"returned: %s\n", pkgname, strerror(errno));
return rv;
}
free(buf);

View File

@ -84,9 +84,7 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
(void)arg;
(void)loop_done;
if (!prop_dictionary_get_bool(obj, "automatic-install", &automatic))
return EINVAL;
prop_dictionary_get_bool(obj, "automatic-install", &automatic);
if (!automatic)
return 0;
@ -132,11 +130,7 @@ add_orphan:
if (orphan == NULL)
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj, "pkgname",
&orphan->pkgname)) {
free(orphan);
return errno;
}
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &orphan->pkgname);
orphan->dict = prop_dictionary_copy(obj);
SIMPLEQ_INSERT_TAIL(&orphan_list, orphan, chain);

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009 Juan Romero Pardines.
* Copyright (c) 2009-2010 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -39,8 +39,7 @@
* These functions will purge an specified package or all packages.
* Only packages in XBPS_PKG_STATE_CONFIG_FILES state will be processed
* (unless overriden). Package purging steps:
* - Its <b>post-remove</b> target specified in the REMOVE script
* will be executed.
*
* - Unmodified configuration files and directories containing them
* will be removed (if empty).
* - Its metadata directory and all its files will be removed.
@ -118,15 +117,12 @@ xbps_purge_all_pkgs(void)
}
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
rv = errno;
break;
}
if ((rv = xbps_get_pkg_state_dictionary(obj, &state)) != 0)
break;
if (state != XBPS_PKG_STATE_CONFIG_FILES)
continue;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if ((rv = xbps_purge_pkg(pkgname, false)) != 0)
break;
}
@ -140,7 +136,7 @@ out:
int
xbps_purge_pkg(const char *pkgname, bool check_state)
{
prop_dictionary_t dict;
prop_dictionary_t dict, pkgd;
char *path;
int rv = 0, flags;
pkg_state_t state = 0;
@ -148,39 +144,49 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
assert(pkgname != NULL);
flags = xbps_get_flags();
/*
* Firstly let's get the pkg dictionary from regpkgdb.
*/
if ((dict = xbps_regpkgs_dictionary_init()) == NULL)
return errno;
pkgd = xbps_find_pkg_in_dict_by_name(dict, "packages", pkgname);
if (pkgd == NULL) {
rv = errno;
goto out;
}
if (check_state) {
/*
* Skip packages that aren't in "config-files" state.
*/
if ((rv = xbps_get_pkg_state_installed(pkgname, &state)) != 0)
return rv;
if ((rv = xbps_get_pkg_state_dictionary(pkgd, &state)) != 0)
goto out;
if (state != XBPS_PKG_STATE_CONFIG_FILES)
return 0;
goto out;
}
/*
* Remove unmodified configuration files.
*/
path = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(),
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
if (path == NULL)
return errno;
path = xbps_xasprintf("%s/%s/metadata/%s/%s",
xbps_get_rootdir(), XBPS_META_PATH, pkgname, XBPS_PKGFILES);
if (path == NULL) {
rv = errno;
goto out;
}
dict = prop_dictionary_internalize_from_zfile(path);
if (dict == NULL) {
free(path);
return errno;
rv = errno;
goto out;
}
free(path);
if ((rv = xbps_remove_pkg_files(dict, "conf_files")) != 0) {
prop_object_release(dict);
return rv;
}
/* Also try to remove empty dirs used in conf_files */
if ((rv = xbps_remove_pkg_files(dict, "dirs")) != 0) {
prop_object_release(dict);
return rv;
goto out;
}
prop_object_release(dict);
@ -196,5 +202,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
}
}
out:
xbps_regpkgs_dictionary_release();
return rv;
}

View File

@ -54,22 +54,15 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool automatic)
if (plist == NULL)
return EINVAL;
if (!prop_dictionary_get_cstring_nocopy(pkgrd, "pkgname", &pkgname)) {
free(plist);
return EINVAL;
}
if (!prop_dictionary_get_cstring_nocopy(pkgrd, "version", &version)) {
free(plist);
return EINVAL;
}
if (!prop_dictionary_get_cstring_nocopy(pkgrd, "short_desc", &desc)) {
free(plist);
return EINVAL;
}
if (!prop_dictionary_get_cstring_nocopy(pkgrd, "pkgver", &pkgver)) {
free(plist);
return EINVAL;
}
prop_dictionary_get_cstring_nocopy(pkgrd, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkgrd, "version", &version);
prop_dictionary_get_cstring_nocopy(pkgrd, "short_desc", &desc);
prop_dictionary_get_cstring_nocopy(pkgrd, "pkgver", &pkgver);
assert(pkgname != NULL);
assert(version != NULL);
assert(desc != NULL);
assert(pkgver != NULL);
if ((dict = prop_dictionary_internalize_from_zfile(plist)) != NULL) {
pkgd = xbps_find_pkg_in_dict_by_name(dict,

View File

@ -29,6 +29,7 @@
#include <string.h>
#include <errno.h>
#include <dirent.h>
#include <libgen.h>
#include <xbps_api.h>
@ -75,8 +76,8 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
prop_array_t array;
prop_object_iterator_t iter;
prop_object_t obj;
const char *file, *sha256;
char *path = NULL;
const char *file, *sha256, *curobj = NULL;
char *dname = NULL, *path = NULL;
int flags = 0, rv = 0;
assert(dict != NULL);
@ -92,11 +93,17 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
if (iter == NULL)
return errno;
if (strcmp(key, "files") == 0)
curobj = "file";
else if (strcmp(key, "conf_files") == 0)
curobj = "configuration file";
else if (strcmp(key, "links") == 0)
curobj = "link";
else if (strcmp(key, "dirs") == 0)
curobj = "directory";
while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj, "file", &file)) {
rv = errno;
break;
}
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
path = xbps_xasprintf("%s/%s", xbps_get_rootdir(), file);
if (path == NULL) {
rv = errno;
@ -108,12 +115,8 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
* Check SHA256 hash in regular files and
* configuration files.
*/
if (!prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256)) {
free(path);
rv = errno;
break;
}
prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256);
rv = xbps_check_file_hash(path, sha256);
if (rv == ENOENT) {
fprintf(stderr,
@ -144,38 +147,40 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
free(path);
break;
}
} else if (strcmp(key, "dirs") == 0) {
if ((rv = rmdir(path)) == -1) {
rv = 0;
if (errno == ENOTEMPTY) {
free(path);
continue;
}
if (flags & XBPS_FLAG_VERBOSE) {
fprintf(stderr,
"WARNING: can't remove "
"directory %s (%s)\n", file,
strerror(errno));
free(path);
continue;
}
}
}
if (strcmp(key, "dirs")) {
if ((rv = remove(path)) == -1) {
/*
* Remove the object if possible.
*/
if (remove(path) == -1) {
if (flags & XBPS_FLAG_VERBOSE)
fprintf(stderr,
"WARNING: can't remove %s %s "
"(%s)\n", curobj, file, strerror(errno));
} else {
/* Success */
if (flags & XBPS_FLAG_VERBOSE)
printf("Removed %s: %s\n", curobj, file);
}
/*
* When purging a package, also remove the directory where
* the conf_files are living on.
*/
if (strcmp(key, "conf_files") == 0) {
dname = dirname(path);
if (rmdir(dname) == -1) {
if (errno != ENOTEMPTY) {
fprintf(stderr,
"WARNING: can't remove %s %s "
"(%s)\n", curobj, file,
strerror(errno));
}
} else {
if (flags & XBPS_FLAG_VERBOSE)
fprintf(stderr,
"WARNING: can't remove %s "
"(%s)\n", file, strerror(errno));
rv = 0;
free(path);
continue;
printf("Removed empty directory: "
"%s\n", dname);
}
}
if (flags & XBPS_FLAG_VERBOSE)
printf("Removed: %s\n", file);
free(path);
}
prop_object_iterator_release(iter);
@ -187,10 +192,8 @@ int
xbps_remove_pkg(const char *pkgname, const char *version, bool update)
{
prop_dictionary_t dict;
const char *rootdir = xbps_get_rootdir();
char *path, *buf;
int rv = 0;
bool prepostf = false;
assert(pkgname != NULL);
assert(version != NULL);
@ -201,34 +204,27 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
if (!xbps_check_is_installed_pkgname(pkgname))
return ENOENT;
if (strcmp(rootdir, "") == 0)
rootdir = "/";
if (chdir(rootdir) == -1)
return errno;
buf = xbps_xasprintf(".%s/metadata/%s/REMOVE",
XBPS_META_PATH, pkgname);
if (buf == NULL)
return errno;
if (chdir(xbps_get_rootdir()) == -1) {
free(buf);
return errno;
}
/*
* Find out if the REMOVE file exists.
* Run the pre remove action.
*/
if (access(buf, X_OK) == 0) {
/*
* Run the pre remove action.
*/
prepostf = true;
rv = xbps_file_chdir_exec(rootdir, buf, "pre", pkgname,
version, update ? "yes" : "no", NULL);
if (rv != 0) {
fprintf(stderr,
"%s: prerm action target error (%s)\n", pkgname,
strerror(errno));
free(buf);
return rv;
}
rv = xbps_file_exec(buf, "pre", pkgname, version,
update ? "yes" : "no", NULL);
if (rv != 0 && errno != ENOENT) {
fprintf(stderr,
"%s: prerm action target error (%s)\n", pkgname,
strerror(errno));
free(buf);
return rv;
}
/*
@ -244,55 +240,51 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
/*
* Remove links, files and dirs.
*/
path = xbps_xasprintf("%s/%s/metadata/%s/%s",
rootdir, XBPS_META_PATH, pkgname, XBPS_PKGFILES);
path = xbps_xasprintf(".%s/metadata/%s/%s",
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
if (path == NULL) {
free(buf);
return errno;
}
dict = prop_dictionary_internalize_from_zfile(path);
if (dict == NULL) {
free(buf);
free(path);
free(buf);
return errno;
}
free(path);
/* Remove links */
if ((rv = xbps_remove_pkg_files(dict, "links")) != 0) {
free(buf);
prop_object_release(dict);
free(buf);
return rv;
}
/* Remove regular files */
if ((rv = xbps_remove_pkg_files(dict, "files")) != 0) {
free(buf);
prop_object_release(dict);
free(buf);
return rv;
}
/* Remove dirs */
if ((rv = xbps_remove_pkg_files(dict, "dirs")) != 0) {
free(buf);
prop_object_release(dict);
free(buf);
return rv;
}
prop_object_release(dict);
/*
* Run the post remove action if REMOVE file is there
* and we aren't updating a package.
* Execute the post REMOVE action if file exists and we aren't
* updating the package.
*/
if (update == false && prepostf) {
rv = xbps_file_chdir_exec(rootdir, buf, "post",
pkgname, version, NULL);
if (rv != 0) {
fprintf(stderr,
"%s: postrm action target error (%s)\n",
pkgname, strerror(errno));
free(buf);
return rv;
}
rv = xbps_file_exec(buf, "post", pkgname, version, "no", NULL);
if (rv != 0 && errno != ENOENT) {
fprintf(stderr,
"%s: postrm action target error (%s)\n", pkgname,
strerror(errno));
free(buf);
return rv;
}
free(buf);

View File

@ -161,9 +161,7 @@ xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg)
char *rdepname;
int rv = 0;
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgver", &pkgver))
return errno;
prop_dictionary_get_cstring_nocopy(pkg, "pkgver", &pkgver);
rdeps = prop_dictionary_get(pkg, "run_depends");
if (rdeps == NULL || prop_array_count(rdeps) == 0)
return EINVAL;
@ -195,13 +193,8 @@ xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg)
* current run dependency.
*/
while ((obj2 = prop_object_iterator_next(iter2)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj2,
"pkgname", &reqname)) {
free(rdepname);
prop_object_iterator_release(iter2);
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(obj2,
"pkgname", &reqname);
if (strcmp(rdepname, reqname) == 0) {
rv = add_pkg_into_reqby(obj2, pkgver);
if (rv == EEXIST)

View File

@ -83,8 +83,8 @@ get_state(prop_dictionary_t dict)
assert(dict != NULL);
if (!prop_dictionary_get_cstring_nocopy(dict, "state", &state_str))
return 0;
prop_dictionary_get_cstring_nocopy(dict, "state", &state_str);
assert(state_str != NULL);
if (strcmp(state_str, "unpacked") == 0)
state = XBPS_PKG_STATE_UNPACKED;

View File

@ -90,12 +90,13 @@ set_extract_flags(int *flags, bool update)
* the consumer.
*/
static int
unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg,
const char *pkgname, const char *version)
{
prop_dictionary_t filesd = NULL, old_filesd = NULL;
struct archive_entry *entry;
size_t entry_idx = 0;
const char *pkgname, *version, *rootdir, *entry_str, *transact;
const char *rootdir, *entry_str, *transact;
char *buf;
int rv, flags, lflags;
bool preserve, skip_entry, update, replace_files_in_pkg_update;
@ -109,22 +110,11 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
rootdir = xbps_get_rootdir();
flags = xbps_get_flags();
if (strcmp(rootdir, "") == 0)
rootdir = "/";
if (chdir(rootdir) == -1)
return errno;
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname))
return errno;
if (!prop_dictionary_get_cstring_nocopy(pkg, "version", &version))
return errno;
prop_dictionary_get_bool(pkg, "preserve", &preserve);
if (!prop_dictionary_get_cstring_nocopy(pkg, "trans-action",
&transact))
return errno;
prop_dictionary_get_cstring_nocopy(pkg, "trans-action", &transact);
if (strcmp(transact, "update") == 0)
update = true;
@ -138,8 +128,8 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
XBPS_META_PATH, pkgname);
if (buf == NULL)
return errno;
if (access(buf, R_OK|X_OK) == 0) {
if (unlink(buf) == -1) {
if (unlink(buf) == -1) {
if (errno != ENOENT) {
free(buf);
return errno;
}
@ -149,8 +139,8 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
XBPS_META_PATH, pkgname);
if (buf == NULL)
return errno;
if (access(buf, R_OK|X_OK) == 0) {
if (unlink(buf) == -1) {
if (unlink(buf) == -1) {
if (errno != ENOENT) {
free(buf);
return errno;
}
@ -183,7 +173,7 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
}
}
rv = xbps_file_chdir_exec(rootdir, buf, "pre",
rv = xbps_file_exec(buf, "pre",
pkgname, version, update ? "yes" : "no", NULL);
if (rv != 0) {
free(buf);
@ -380,17 +370,17 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
int
xbps_unpack_binary_pkg(prop_dictionary_t pkg)
{
const char *pkgname, *repoloc;
const char *pkgname, *repoloc, *version;
struct archive *ar = NULL;
char *binfile = NULL;
int pkg_fd, rv = 0;
assert(pkg != NULL);
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname))
return errno;
if (!prop_dictionary_get_cstring_nocopy(pkg, "repository", &repoloc))
return errno;
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkg, "repository", &repoloc);
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
binfile = xbps_get_binpkg_local_path(pkg, repoloc);
if (binfile == NULL)
return EINVAL;
@ -416,7 +406,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg)
ARCHIVE_READ_BLOCKSIZE)) != 0)
goto out;
if ((rv = unpack_archive_fini(ar, pkg)) != 0)
if ((rv = unpack_archive_fini(ar, pkg, pkgname, version)) != 0)
goto out;
/*

View File

@ -207,9 +207,7 @@ xbps_find_pkg_in_dict_by_name(prop_dictionary_t dict,
return NULL;
while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &dpkgn))
break;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &dpkgn);
if (strcmp(dpkgn, pkgname) == 0)
break;
}
@ -237,9 +235,7 @@ xbps_find_pkg_in_dict_by_pattern(prop_dictionary_t dict,
return NULL;
while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver))
break;
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
if (xbps_pkgpattern_match(pkgver, __UNCONST(pattern)))
break;
}
@ -347,11 +343,7 @@ xbps_remove_pkg_from_dict(prop_dictionary_t dict, const char *key,
/* Iterate over the array of dictionaries to find its index. */
while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj, "pkgname",
&curpkgname)) {
prop_object_iterator_release(iter);
return errno;
}
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgname);
if ((curpkgname && (strcmp(curpkgname, pkgname) == 0))) {
found = true;
break;

View File

@ -46,13 +46,8 @@ store_dependency(prop_dictionary_t trans_dict, prop_dictionary_t repo_pkg_dict,
/*
* Get some info about dependencies and current repository.
*/
if (!prop_dictionary_get_cstring_nocopy(repo_pkg_dict,
"pkgname", &pkgname))
return errno;
if (!prop_dictionary_get_cstring_nocopy(repo_pkg_dict,
"pkgver", &pkgver))
return errno;
prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgver", &pkgver);
dict = prop_dictionary_copy(repo_pkg_dict);
if (dict == NULL)
@ -318,13 +313,8 @@ find_repo_deps(prop_dictionary_t trans_dict, prop_dictionary_t repo_dict,
break;
}
} else if (curpkgd) {
if (!prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkg_queued)) {
DPRINTF(("pkgver failed %s\n", reqpkg));
free(pkgname);
rv = errno;
break;
}
prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkg_queued);
if (xbps_pkgpattern_match(pkg_queued,
__UNCONST(reqpkg))) {
if (flags & XBPS_FLAG_VERBOSE)
@ -370,12 +360,7 @@ find_repo_deps(prop_dictionary_t trans_dict, prop_dictionary_t repo_dict,
* If version in repo does not satisfy the rundep, pass
* to the next rundep.
*/
if (!prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &repo_pkgver)) {
free(pkgname);
rv = errno;
break;
}
prop_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &repo_pkgver);
if (xbps_pkgpattern_match(repo_pkgver, __UNCONST(reqpkg)) < 1) {
free(pkgname);
continue;
@ -483,13 +468,8 @@ xbps_repository_find_pkg_deps(prop_dictionary_t trans_dict,
if (pkg_rdeps == NULL)
return 0;
if (!prop_dictionary_get_cstring_nocopy(repo_pkg_dict,
"pkgname", &pkgname))
return errno;
if (!prop_dictionary_get_cstring_nocopy(repo_pkg_dict,
"pkgver", &pkgver))
return errno;
prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgver", &pkgver);
if ((rv = xbps_repository_pool_init()) != 0)
return rv;

View File

@ -117,29 +117,17 @@ compute_transaction_sizes(void)
return -1;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"trans-action", &tract)) {
rv = -1;
goto out;
}
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
/*
* Skip pkgs that need to be configured.
*/
if (strcmp(tract, "configure") == 0)
continue;
if (!prop_dictionary_get_uint64(obj,
"filename-size", &tsize)) {
rv = -1;
goto out;
}
prop_dictionary_get_uint64(obj, "filename-size", &tsize);
dlsize += tsize;
tsize = 0;
if (!prop_dictionary_get_uint64(obj,
"installed_size", &tsize)) {
rv = -1;
goto out;
}
prop_dictionary_get_uint64(obj, "installed_size", &tsize);
instsize += tsize;
tsize = 0;
}
@ -258,11 +246,7 @@ xbps_repository_update_allpkgs(void)
* installed packages.
*/
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
rv = errno;
break;
}
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
rv = xbps_repository_update_pkg(pkgname, obj);
if (rv == ENOENT)
continue;
@ -324,16 +308,10 @@ xbps_repository_update_pkg(const char *pkgname, prop_dictionary_t instpkg)
* Check if version in repository is greater than
* the version currently installed.
*/
if (!prop_dictionary_get_cstring_nocopy(instpkg,
"version", &instver)) {
rv = errno;
goto out;
}
if (!prop_dictionary_get_cstring_nocopy(pkgrd,
"version", &repover)) {
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(instpkg,
"version", &instver);
prop_dictionary_get_cstring_nocopy(pkgrd,
"version", &repover);
if (xbps_cmpver(repover, instver) > 0) {
if (flags & XBPS_FLAG_VERBOSE) {
printf("Found '%s-%s' in repository "

View File

@ -167,10 +167,8 @@ xbps_repository_get_path_from_pkg_dict(prop_dictionary_t d, const char *uri)
if (path)
return path;
if (!prop_dictionary_get_cstring_nocopy(d, "architecture", &arch))
return NULL;
if (!prop_dictionary_get_cstring_nocopy(d, "filename", &filen))
return NULL;
prop_dictionary_get_cstring_nocopy(d, "architecture", &arch);
prop_dictionary_get_cstring_nocopy(d, "filename", &filen);
return xbps_xasprintf("%s/%s/%s", uri, arch, filen);
}

View File

@ -104,16 +104,8 @@ again:
* Order all deps by looking at its run_depends array.
*/
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
rv = errno;
goto out;
}
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver)) {
rv = errno;
goto out;
}
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
DPRINTF(("Sorting package: %s\n", pkgver));
if (find_sorteddep_by_name(pkgname) != NULL) {
DPRINTF(("Skipping %s already queued.\n", pkgname));

View File

@ -154,13 +154,11 @@ xbps_check_is_repo_string_remote(const char *uri)
static const char *
xbps_get_pkgver_from_dict(prop_dictionary_t d)
{
const char *pkgver;
const char *pkgver = NULL;
assert(d != NULL);
if (!prop_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver))
return NULL;
prop_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver);
return pkgver;
}
@ -379,10 +377,8 @@ xbps_get_binpkg_local_path(prop_dictionary_t pkgd, const char *repoloc)
{
const char *filen, *arch, *cdir;
if (!prop_dictionary_get_cstring_nocopy(pkgd, "filename", &filen))
return NULL;
if (!prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch))
return NULL;
prop_dictionary_get_cstring_nocopy(pkgd, "filename", &filen);
prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch);
cdir = xbps_get_cachedir();
if (cdir == NULL)
return NULL;
@ -419,7 +415,7 @@ const char *
xbps_get_rootdir(void)
{
if (rootdir == NULL)
rootdir = "";
rootdir = "/";
return rootdir;
}