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:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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", ®ver)) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(curpkgd, "version", ®ver);
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user