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

View File

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

View File

@ -38,8 +38,7 @@ pkg_remove_and_purge(const char *pkgname, const char *version, bool purge)
{ {
int rv = 0; int rv = 0;
printf("Removing package %s-%s ... ", pkgname, version); printf("Removing package %s-%s ...\n", pkgname, version);
(void)fflush(stdout);
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0) { if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0) {
fprintf(stderr, "\nE: unable to remove %s-%s (%s).\n", 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; return rv;
} }
if (purge) { if (purge) {
printf("purging ... "); printf(" Purging ... ");
(void)fflush(stdout); (void)fflush(stdout);
if ((rv = xbps_purge_pkg(pkgname, false)) != 0) { if ((rv = xbps_purge_pkg(pkgname, false)) != 0) {
fprintf(stderr, "\nE: unable to purge %s-%s " 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)); strerror(errno));
return rv; return rv;
} }
printf("done.\n");
} }
printf("done.\n");
return rv; return rv;
} }
@ -95,11 +94,7 @@ xbps_autoremove_pkgs(bool force, bool purge, bool only_show)
printf("The following packages were installed automatically\n" printf("The following packages were installed automatically\n"
"(as dependencies) and aren't needed anymore:\n\n"); "(as dependencies) and aren't needed anymore:\n\n");
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj, prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
"pkgver", &pkgver)) {
rv = errno;
goto out;
}
cols += strlen(pkgver) + 4; cols += strlen(pkgver) + 4;
if (cols <= 80) { if (cols <= 80) {
if (first == false) { 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) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj, prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
"pkgname", &pkgname)) { prop_dictionary_get_cstring_nocopy(obj, "version", &version);
rv = errno;
goto out;
}
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version)) {
rv = errno;
goto out;
}
if ((rv = pkg_remove_and_purge(pkgname, version, purge)) != 0) if ((rv = pkg_remove_and_purge(pkgname, version, purge)) != 0)
goto out; 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]); printf("Package %s is not installed.\n", argv[i]);
continue; continue;
} }
if (!prop_dictionary_get_cstring_nocopy(dict, "version", prop_dictionary_get_cstring_nocopy(dict, "version", &version);
&version))
return errno;
found = true; found = true;
reqby = prop_dictionary_get(dict, "requiredby"); reqby = prop_dictionary_get(dict, "requiredby");
if (reqby != NULL && prop_array_count(reqby) > 0) { 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); "file, skipping!\n", file, XBPS_PKGPROPS);
goto out; goto out;
} }
if (!prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname", &pkgname)) { prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname", &pkgname);
prop_object_release(newpkgd); prop_dictionary_get_cstring_nocopy(newpkgd, "version", &version);
rv = errno;
goto out;
}
if (!prop_dictionary_get_cstring_nocopy(newpkgd, "version", &version)) {
prop_object_release(newpkgd);
rv = errno;
goto out;
}
/* /*
* Check if this package exists already in the index, but first * Check if this package exists already in the index, but first
* checking the version. If current package version is greater * 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; goto out;
} }
} else if (curpkgd) { } else if (curpkgd) {
if (!prop_dictionary_get_cstring_nocopy(curpkgd, prop_dictionary_get_cstring_nocopy(curpkgd, "version", &regver);
"version", &regver)) {
prop_object_release(newpkgd);
rv = errno;
goto out;
}
if (xbps_cmpver(version, regver) <= 0) { if (xbps_cmpver(version, regver) <= 0) {
fprintf(stderr, "W: skipping %s. %s-%s already " fprintf(stderr, "W: skipping %s. %s-%s already "
"registered.\n", filen, pkgname, regver); "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 * in package index, remove outdated binpkg file
* and its dictionary from the pkg index. * and its dictionary from the pkg index.
*/ */
if (!prop_dictionary_get_cstring_nocopy(curpkgd, prop_dictionary_get_cstring_nocopy(curpkgd,
"filename", &oldfilen)) { "filename", &oldfilen);
prop_object_release(newpkgd);
rv = errno;
goto out;
}
oldfilepath = xbps_xasprintf("%s/%s", filedir, oldfilen); oldfilepath = xbps_xasprintf("%s/%s", filedir, oldfilen);
if (oldfilepath == NULL) { if (oldfilepath == NULL) {
prop_object_release(newpkgd); prop_object_release(newpkgd);

View File

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

View File

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

View File

@ -209,10 +209,7 @@ main(int argc, char **argv)
if (dict == NULL) if (dict == NULL)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
if (!prop_dictionary_get_cstring_nocopy(dict, "version", prop_dictionary_get_cstring_nocopy(dict, "version", &version);
&version))
exit(EXIT_FAILURE);
printf("%s\n", version); printf("%s\n", version);
prop_object_release(dict); 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"); iter2 = xbps_get_array_iter_from_dict(forigd, "conf_files");
if (iter2 != NULL) { if (iter2 != NULL) {
while ((obj2 = prop_object_iterator_next(iter2))) { while ((obj2 = prop_object_iterator_next(iter2))) {
if (!prop_dictionary_get_cstring_nocopy(obj2, prop_dictionary_get_cstring_nocopy(obj2,
"file", &cffile)) { "file", &cffile);
prop_object_iterator_release(iter2);
rv = errno;
goto out;
}
buf = xbps_xasprintf(".%s", cffile); buf = xbps_xasprintf(".%s", cffile);
if (buf == NULL) { if (buf == NULL) {
prop_object_iterator_release(iter2); 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. * Compare original, installed and new hash for current file.
*/ */
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj, prop_dictionary_get_cstring_nocopy(obj, "file", &cffile);
"file", &cffile)) {
prop_object_iterator_release(iter);
return errno;
}
buf = xbps_xasprintf(".%s", cffile); buf = xbps_xasprintf(".%s", cffile);
if (buf == NULL) { if (buf == NULL) {
prop_object_iterator_release(iter); 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); sha256_cur = xbps_get_file_hash(buf);
free(buf); free(buf);
if (!prop_dictionary_get_cstring_nocopy(obj, prop_dictionary_get_cstring_nocopy(obj, "sha256", &sha256_new);
"sha256", &sha256_new)) {
rv = EINVAL;
break;
}
if (sha256_cur == NULL) { if (sha256_cur == NULL) {
if (errno == ENOENT) { if (errno == ENOENT) {
/* /*

View File

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

View File

@ -84,9 +84,7 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
(void)arg; (void)arg;
(void)loop_done; (void)loop_done;
if (!prop_dictionary_get_bool(obj, "automatic-install", &automatic)) prop_dictionary_get_bool(obj, "automatic-install", &automatic);
return EINVAL;
if (!automatic) if (!automatic)
return 0; return 0;
@ -132,11 +130,7 @@ add_orphan:
if (orphan == NULL) if (orphan == NULL)
return errno; return errno;
if (!prop_dictionary_get_cstring_nocopy(obj, "pkgname", prop_dictionary_get_cstring_nocopy(obj, "pkgname", &orphan->pkgname);
&orphan->pkgname)) {
free(orphan);
return errno;
}
orphan->dict = prop_dictionary_copy(obj); orphan->dict = prop_dictionary_copy(obj);
SIMPLEQ_INSERT_TAIL(&orphan_list, orphan, chain); 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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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. * These functions will purge an specified package or all packages.
* Only packages in XBPS_PKG_STATE_CONFIG_FILES state will be processed * Only packages in XBPS_PKG_STATE_CONFIG_FILES state will be processed
* (unless overriden). Package purging steps: * (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 * - Unmodified configuration files and directories containing them
* will be removed (if empty). * will be removed (if empty).
* - Its metadata directory and all its files will be removed. * - 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) { 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) if ((rv = xbps_get_pkg_state_dictionary(obj, &state)) != 0)
break; break;
if (state != XBPS_PKG_STATE_CONFIG_FILES) if (state != XBPS_PKG_STATE_CONFIG_FILES)
continue; continue;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if ((rv = xbps_purge_pkg(pkgname, false)) != 0) if ((rv = xbps_purge_pkg(pkgname, false)) != 0)
break; break;
} }
@ -140,7 +136,7 @@ out:
int int
xbps_purge_pkg(const char *pkgname, bool check_state) xbps_purge_pkg(const char *pkgname, bool check_state)
{ {
prop_dictionary_t dict; prop_dictionary_t dict, pkgd;
char *path; char *path;
int rv = 0, flags; int rv = 0, flags;
pkg_state_t state = 0; pkg_state_t state = 0;
@ -148,39 +144,49 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
assert(pkgname != NULL); assert(pkgname != NULL);
flags = xbps_get_flags(); 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) { if (check_state) {
/* /*
* Skip packages that aren't in "config-files" state. * Skip packages that aren't in "config-files" state.
*/ */
if ((rv = xbps_get_pkg_state_installed(pkgname, &state)) != 0) if ((rv = xbps_get_pkg_state_dictionary(pkgd, &state)) != 0)
return rv; goto out;
if (state != XBPS_PKG_STATE_CONFIG_FILES) if (state != XBPS_PKG_STATE_CONFIG_FILES)
return 0; goto out;
} }
/* /*
* Remove unmodified configuration files. * Remove unmodified configuration files.
*/ */
path = xbps_xasprintf("%s/%s/metadata/%s/%s", xbps_get_rootdir(), path = xbps_xasprintf("%s/%s/metadata/%s/%s",
XBPS_META_PATH, pkgname, XBPS_PKGFILES); xbps_get_rootdir(), XBPS_META_PATH, pkgname, XBPS_PKGFILES);
if (path == NULL) if (path == NULL) {
return errno; rv = errno;
goto out;
}
dict = prop_dictionary_internalize_from_zfile(path); dict = prop_dictionary_internalize_from_zfile(path);
if (dict == NULL) { if (dict == NULL) {
free(path); free(path);
return errno; rv = errno;
goto out;
} }
free(path); free(path);
if ((rv = xbps_remove_pkg_files(dict, "conf_files")) != 0) { if ((rv = xbps_remove_pkg_files(dict, "conf_files")) != 0) {
prop_object_release(dict); prop_object_release(dict);
return rv; goto out;
}
/* 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;
} }
prop_object_release(dict); prop_object_release(dict);
@ -196,5 +202,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
} }
} }
out:
xbps_regpkgs_dictionary_release();
return rv; return rv;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -207,9 +207,7 @@ xbps_find_pkg_in_dict_by_name(prop_dictionary_t dict,
return NULL; return NULL;
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj, prop_dictionary_get_cstring_nocopy(obj, "pkgname", &dpkgn);
"pkgname", &dpkgn))
break;
if (strcmp(dpkgn, pkgname) == 0) if (strcmp(dpkgn, pkgname) == 0)
break; break;
} }
@ -237,9 +235,7 @@ xbps_find_pkg_in_dict_by_pattern(prop_dictionary_t dict,
return NULL; return NULL;
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj, prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
"pkgver", &pkgver))
break;
if (xbps_pkgpattern_match(pkgver, __UNCONST(pattern))) if (xbps_pkgpattern_match(pkgver, __UNCONST(pattern)))
break; 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. */ /* Iterate over the array of dictionaries to find its index. */
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj, "pkgname", prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgname);
&curpkgname)) {
prop_object_iterator_release(iter);
return errno;
}
if ((curpkgname && (strcmp(curpkgname, pkgname) == 0))) { if ((curpkgname && (strcmp(curpkgname, pkgname) == 0))) {
found = true; found = true;
break; 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. * Get some info about dependencies and current repository.
*/ */
if (!prop_dictionary_get_cstring_nocopy(repo_pkg_dict, prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgname", &pkgname);
"pkgname", &pkgname)) prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgver", &pkgver);
return errno;
if (!prop_dictionary_get_cstring_nocopy(repo_pkg_dict,
"pkgver", &pkgver))
return errno;
dict = prop_dictionary_copy(repo_pkg_dict); dict = prop_dictionary_copy(repo_pkg_dict);
if (dict == NULL) if (dict == NULL)
@ -318,13 +313,8 @@ find_repo_deps(prop_dictionary_t trans_dict, prop_dictionary_t repo_dict,
break; break;
} }
} else if (curpkgd) { } else if (curpkgd) {
if (!prop_dictionary_get_cstring_nocopy(curpkgd, prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkg_queued)) { "pkgver", &pkg_queued);
DPRINTF(("pkgver failed %s\n", reqpkg));
free(pkgname);
rv = errno;
break;
}
if (xbps_pkgpattern_match(pkg_queued, if (xbps_pkgpattern_match(pkg_queued,
__UNCONST(reqpkg))) { __UNCONST(reqpkg))) {
if (flags & XBPS_FLAG_VERBOSE) 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 * If version in repo does not satisfy the rundep, pass
* to the next rundep. * to the next rundep.
*/ */
if (!prop_dictionary_get_cstring_nocopy(curpkgd, prop_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &repo_pkgver);
"pkgver", &repo_pkgver)) {
free(pkgname);
rv = errno;
break;
}
if (xbps_pkgpattern_match(repo_pkgver, __UNCONST(reqpkg)) < 1) { if (xbps_pkgpattern_match(repo_pkgver, __UNCONST(reqpkg)) < 1) {
free(pkgname); free(pkgname);
continue; continue;
@ -483,13 +468,8 @@ xbps_repository_find_pkg_deps(prop_dictionary_t trans_dict,
if (pkg_rdeps == NULL) if (pkg_rdeps == NULL)
return 0; return 0;
if (!prop_dictionary_get_cstring_nocopy(repo_pkg_dict, prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgname", &pkgname);
"pkgname", &pkgname)) prop_dictionary_get_cstring_nocopy(repo_pkg_dict, "pkgver", &pkgver);
return errno;
if (!prop_dictionary_get_cstring_nocopy(repo_pkg_dict,
"pkgver", &pkgver))
return errno;
if ((rv = xbps_repository_pool_init()) != 0) if ((rv = xbps_repository_pool_init()) != 0)
return rv; return rv;

View File

@ -117,29 +117,17 @@ compute_transaction_sizes(void)
return -1; return -1;
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj, prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
"trans-action", &tract)) {
rv = -1;
goto out;
}
/* /*
* Skip pkgs that need to be configured. * Skip pkgs that need to be configured.
*/ */
if (strcmp(tract, "configure") == 0) if (strcmp(tract, "configure") == 0)
continue; continue;
if (!prop_dictionary_get_uint64(obj, prop_dictionary_get_uint64(obj, "filename-size", &tsize);
"filename-size", &tsize)) {
rv = -1;
goto out;
}
dlsize += tsize; dlsize += tsize;
tsize = 0; tsize = 0;
if (!prop_dictionary_get_uint64(obj, prop_dictionary_get_uint64(obj, "installed_size", &tsize);
"installed_size", &tsize)) {
rv = -1;
goto out;
}
instsize += tsize; instsize += tsize;
tsize = 0; tsize = 0;
} }
@ -258,11 +246,7 @@ xbps_repository_update_allpkgs(void)
* installed packages. * installed packages.
*/ */
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj, prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
"pkgname", &pkgname)) {
rv = errno;
break;
}
rv = xbps_repository_update_pkg(pkgname, obj); rv = xbps_repository_update_pkg(pkgname, obj);
if (rv == ENOENT) if (rv == ENOENT)
continue; continue;
@ -324,16 +308,10 @@ xbps_repository_update_pkg(const char *pkgname, prop_dictionary_t instpkg)
* Check if version in repository is greater than * Check if version in repository is greater than
* the version currently installed. * the version currently installed.
*/ */
if (!prop_dictionary_get_cstring_nocopy(instpkg, prop_dictionary_get_cstring_nocopy(instpkg,
"version", &instver)) { "version", &instver);
rv = errno; prop_dictionary_get_cstring_nocopy(pkgrd,
goto out; "version", &repover);
}
if (!prop_dictionary_get_cstring_nocopy(pkgrd,
"version", &repover)) {
rv = errno;
goto out;
}
if (xbps_cmpver(repover, instver) > 0) { if (xbps_cmpver(repover, instver) > 0) {
if (flags & XBPS_FLAG_VERBOSE) { if (flags & XBPS_FLAG_VERBOSE) {
printf("Found '%s-%s' in repository " 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) if (path)
return path; return path;
if (!prop_dictionary_get_cstring_nocopy(d, "architecture", &arch)) prop_dictionary_get_cstring_nocopy(d, "architecture", &arch);
return NULL; prop_dictionary_get_cstring_nocopy(d, "filename", &filen);
if (!prop_dictionary_get_cstring_nocopy(d, "filename", &filen))
return NULL;
return xbps_xasprintf("%s/%s/%s", uri, arch, 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. * Order all deps by looking at its run_depends array.
*/ */
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj, prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
"pkgname", &pkgname)) { prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
rv = errno;
goto out;
}
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver)) {
rv = errno;
goto out;
}
DPRINTF(("Sorting package: %s\n", pkgver)); DPRINTF(("Sorting package: %s\n", pkgver));
if (find_sorteddep_by_name(pkgname) != NULL) { if (find_sorteddep_by_name(pkgname) != NULL) {
DPRINTF(("Skipping %s already queued.\n", pkgname)); 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 * static const char *
xbps_get_pkgver_from_dict(prop_dictionary_t d) xbps_get_pkgver_from_dict(prop_dictionary_t d)
{ {
const char *pkgver; const char *pkgver = NULL;
assert(d != NULL); assert(d != NULL);
if (!prop_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver)) prop_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver);
return NULL;
return pkgver; return pkgver;
} }
@ -379,10 +377,8 @@ xbps_get_binpkg_local_path(prop_dictionary_t pkgd, const char *repoloc)
{ {
const char *filen, *arch, *cdir; const char *filen, *arch, *cdir;
if (!prop_dictionary_get_cstring_nocopy(pkgd, "filename", &filen)) prop_dictionary_get_cstring_nocopy(pkgd, "filename", &filen);
return NULL; prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch);
if (!prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch))
return NULL;
cdir = xbps_get_cachedir(); cdir = xbps_get_cachedir();
if (cdir == NULL) if (cdir == NULL)
return NULL; return NULL;
@ -419,7 +415,7 @@ const char *
xbps_get_rootdir(void) xbps_get_rootdir(void)
{ {
if (rootdir == NULL) if (rootdir == NULL)
rootdir = ""; rootdir = "/";
return rootdir; return rootdir;
} }