Extensively verified that all functions have its return value
checked for any spurious error, this should make the core more safer :-) --HG-- extra : convert_revision : xtraeme%40gmail.com-20091123094651-5prw0bkqmt3y8h23
This commit is contained in:
@@ -64,8 +64,16 @@ xbps_check_pkg_integrity_all(void)
|
||||
return ENOENT;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgname", &pkgname)) {
|
||||
prop_object_iterator_release(iter);
|
||||
return errno;
|
||||
}
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"version", &version)) {
|
||||
prop_object_iterator_release(iter);
|
||||
return errno;
|
||||
}
|
||||
printf("Checking %s-%s ...\n", pkgname, version);
|
||||
if ((rv = xbps_check_pkg_integrity(pkgname)) != 0)
|
||||
nbrokenpkgs++;
|
||||
@@ -177,7 +185,12 @@ xbps_check_pkg_integrity(const char *pkgname)
|
||||
goto out2;
|
||||
}
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"file", &file)) {
|
||||
prop_object_iterator_release(iter);
|
||||
rv = errno;
|
||||
goto out2;
|
||||
}
|
||||
path = xbps_xasprintf("%s/%s",
|
||||
xbps_get_rootdir(), file);
|
||||
if (path == NULL) {
|
||||
@@ -185,8 +198,13 @@ xbps_check_pkg_integrity(const char *pkgname)
|
||||
rv = errno;
|
||||
goto out2;
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"sha256", &sha256);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"sha256", &sha256)) {
|
||||
free(path);
|
||||
prop_object_iterator_release(iter);
|
||||
rv = errno;
|
||||
goto out2;
|
||||
}
|
||||
rv = xbps_check_file_hash(path, sha256);
|
||||
switch (rv) {
|
||||
case 0:
|
||||
@@ -227,7 +245,12 @@ xbps_check_pkg_integrity(const char *pkgname)
|
||||
goto out2;
|
||||
}
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"file", &file)) {
|
||||
prop_object_iterator_release(iter);
|
||||
rv = errno;
|
||||
goto out2;
|
||||
}
|
||||
path = xbps_xasprintf("%s/%s",
|
||||
xbps_get_rootdir(), file);
|
||||
if (path == NULL) {
|
||||
@@ -264,6 +287,11 @@ xbps_check_pkg_integrity(const char *pkgname)
|
||||
}
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
reqpkg = prop_string_cstring_nocopy(obj);
|
||||
if (reqpkg == NULL) {
|
||||
prop_object_iterator_release(iter);
|
||||
rv = EINVAL;
|
||||
goto out2;
|
||||
}
|
||||
if (xbps_check_is_installed_pkg(reqpkg) <= 0) {
|
||||
rv = ENOENT;
|
||||
printf("%s: dependency not satisfied: %s\n",
|
||||
|
||||
@@ -82,7 +82,10 @@ check_pkg_hashes(prop_object_iterator_t iter)
|
||||
|
||||
printf("Checking binary package file(s) integrity...\n");
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgname", &pkgname))
|
||||
return errno;
|
||||
|
||||
state = 0;
|
||||
if (xbps_get_pkg_state_dictionary(obj, &state) != 0)
|
||||
return EINVAL;
|
||||
@@ -90,8 +93,12 @@ check_pkg_hashes(prop_object_iterator_t iter)
|
||||
if (state == XBPS_PKG_STATE_UNPACKED)
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"repository", &repoloc))
|
||||
return errno;
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"filename", &filename))
|
||||
return errno;
|
||||
rv = xbps_check_pkg_file_hash(obj, repoloc);
|
||||
if (rv != 0 && rv != ERANGE) {
|
||||
printf("Unexpected error while checking hash for "
|
||||
@@ -118,16 +125,24 @@ download_package_list(prop_object_iterator_t iter)
|
||||
|
||||
printf("Downloading binary package file(s)...\n");
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"repository", &repoloc))
|
||||
return errno;
|
||||
/*
|
||||
* Skip packages in local repositories.
|
||||
*/
|
||||
if (!xbps_check_is_repo_string_remote(repoloc))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
|
||||
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,
|
||||
"architecture", &arch))
|
||||
return errno;
|
||||
|
||||
repoloc_trans = xbps_get_remote_repo_string(repoloc);
|
||||
if (repoloc_trans == NULL)
|
||||
@@ -139,14 +154,12 @@ download_package_list(prop_object_iterator_t iter)
|
||||
free(repoloc_trans);
|
||||
return errno;
|
||||
}
|
||||
|
||||
lbinfile = xbps_xasprintf("%s/%s", savedir, filename);
|
||||
if (lbinfile == NULL) {
|
||||
free(repoloc_trans);
|
||||
free(savedir);
|
||||
return errno;
|
||||
}
|
||||
|
||||
if (access(lbinfile, R_OK) == 0) {
|
||||
free(savedir);
|
||||
free(lbinfile);
|
||||
@@ -182,7 +195,10 @@ change_repodir:
|
||||
if (savedir == NULL)
|
||||
return errno;
|
||||
|
||||
prop_dictionary_set_cstring(obj, "repository", savedir);
|
||||
if (!prop_dictionary_set_cstring(obj, "repository", savedir)) {
|
||||
free(savedir);
|
||||
return errno;
|
||||
}
|
||||
free(savedir);
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
@@ -199,8 +215,12 @@ show_package_list(prop_object_iterator_t iter, const char *match)
|
||||
bool first = false;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgver", &pkgver))
|
||||
return;
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"trans-action", &tract))
|
||||
return;
|
||||
if (strcmp(match, tract))
|
||||
continue;
|
||||
|
||||
@@ -233,17 +253,24 @@ show_transaction_sizes(prop_object_iterator_t iter)
|
||||
* installed and check the file hash.
|
||||
*/
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_uint64(obj, "filename-size", &tsize);
|
||||
if (!prop_dictionary_get_uint64(obj, "filename-size", &tsize))
|
||||
return errno;
|
||||
|
||||
dlsize += tsize;
|
||||
tsize = 0;
|
||||
prop_dictionary_get_uint64(obj, "installed_size", &tsize);
|
||||
if (!prop_dictionary_get_uint64(obj, "installed_size", &tsize))
|
||||
return errno;
|
||||
|
||||
instsize += tsize;
|
||||
tsize = 0;
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"trans-action", &tract))
|
||||
return errno;
|
||||
|
||||
if (strcmp(tract, "install") == 0)
|
||||
trans_inst = true;
|
||||
else if (strcmp(tract, "update") == 0)
|
||||
@@ -384,8 +411,11 @@ xbps_exec_transaction(const char *pkgname, bool force, bool update)
|
||||
goto out2;
|
||||
}
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(trans->dict,
|
||||
"origin", &trans->originpkgname);
|
||||
if (!prop_dictionary_get_cstring_nocopy(trans->dict,
|
||||
"origin", &trans->originpkgname)) {
|
||||
rv = errno;
|
||||
goto out2;
|
||||
}
|
||||
|
||||
if (update) {
|
||||
/*
|
||||
@@ -434,6 +464,9 @@ replace_packages(prop_object_iterator_t iter, const char *pkgver)
|
||||
*/
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
reppkgn = prop_string_cstring_nocopy(obj);
|
||||
if (reppkgn == NULL)
|
||||
return errno;
|
||||
|
||||
instd = xbps_find_pkg_installed_from_plist(reppkgn);
|
||||
if (instd == NULL)
|
||||
continue;
|
||||
@@ -505,12 +538,22 @@ exec_transaction(struct transaction *trans)
|
||||
* Iterate over the transaction dictionary.
|
||||
*/
|
||||
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
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;
|
||||
prop_dictionary_get_bool(obj, "essential", &essential);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"filename", &filename))
|
||||
return errno;
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"trans-action", &tract))
|
||||
return errno;
|
||||
replaces_iter = xbps_get_array_iter_from_dict(obj, "replaces");
|
||||
|
||||
/*
|
||||
@@ -556,11 +599,17 @@ exec_transaction(struct transaction *trans)
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(instpkgd,
|
||||
"version", &instver);
|
||||
if (!prop_dictionary_get_cstring_nocopy(instpkgd,
|
||||
"version", &instver)) {
|
||||
prop_object_release(instpkgd);
|
||||
return errno;
|
||||
}
|
||||
autoinst = false;
|
||||
prop_dictionary_get_bool(instpkgd, "automatic-install",
|
||||
&autoinst);
|
||||
if (!prop_dictionary_get_bool(instpkgd,
|
||||
"automatic-install", &autoinst)) {
|
||||
prop_object_release(instpkgd);
|
||||
return errno;
|
||||
}
|
||||
prop_object_release(instpkgd);
|
||||
|
||||
/*
|
||||
@@ -618,8 +667,12 @@ exec_transaction(struct transaction *trans)
|
||||
* Configure all unpacked packages.
|
||||
*/
|
||||
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgname", &pkgname))
|
||||
return errno;
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"version", &version))
|
||||
return errno;
|
||||
if ((rv = xbps_configure_pkg(pkgname, version, false)) != 0) {
|
||||
printf("Error configuring package %s (%s)\n",
|
||||
pkgname, strerror(rv));
|
||||
|
||||
@@ -68,7 +68,11 @@ xbps_autoremove_pkgs(void)
|
||||
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) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgver", &pkgver)) {
|
||||
rv = errno;
|
||||
goto out2;
|
||||
}
|
||||
cols += strlen(pkgver) + 4;
|
||||
if (cols <= 80) {
|
||||
if (first == false) {
|
||||
@@ -90,8 +94,16 @@ xbps_autoremove_pkgs(void)
|
||||
}
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgname", &pkgname)) {
|
||||
rv = errno;
|
||||
goto out2;
|
||||
}
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"version", &version)) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
printf("Removing package %s-%s ...\n", pkgname, version);
|
||||
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0)
|
||||
goto out2;
|
||||
@@ -120,7 +132,8 @@ xbps_remove_installed_pkg(const char *pkgname, bool force)
|
||||
printf("Package %s is not installed.\n", pkgname);
|
||||
return 0;
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
|
||||
if (!prop_dictionary_get_cstring_nocopy(dict, "version", &version))
|
||||
return errno;
|
||||
|
||||
reqby = prop_dictionary_get(dict, "requiredby");
|
||||
if (reqby != NULL && prop_array_count(reqby) > 0) {
|
||||
|
||||
@@ -61,10 +61,17 @@ repoidx_getdict(const char *pkgdir)
|
||||
goto out;
|
||||
}
|
||||
|
||||
prop_dictionary_set(dict, "packages", array);
|
||||
if (!prop_dictionary_set(dict, "packages", array)) {
|
||||
prop_object_release(dict);
|
||||
prop_object_release(array);
|
||||
goto out;
|
||||
}
|
||||
prop_object_release(array);
|
||||
prop_dictionary_set_cstring_nocopy(dict,
|
||||
"pkgindex-version", XBPS_PKGINDEX_VERSION);
|
||||
if (!prop_dictionary_set_cstring_nocopy(dict,
|
||||
"pkgindex-version", XBPS_PKGINDEX_VERSION)) {
|
||||
prop_object_release(dict);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
out:
|
||||
free(plist);
|
||||
@@ -128,10 +135,18 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *file)
|
||||
break;
|
||||
}
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname",
|
||||
&pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(newpkgd, "version",
|
||||
&version);
|
||||
if (!prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname",
|
||||
&pkgname)) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
if (!prop_dictionary_get_cstring_nocopy(newpkgd, "version",
|
||||
&version)) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Check if this package exists already in the index, but first
|
||||
* checking the version. If current package version is greater
|
||||
@@ -140,8 +155,12 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *file)
|
||||
*/
|
||||
curpkgd = xbps_find_pkg_in_dict(idxdict, "packages", pkgname);
|
||||
if (curpkgd) {
|
||||
prop_dictionary_get_cstring_nocopy(curpkgd,
|
||||
"version", ®ver);
|
||||
if (!prop_dictionary_get_cstring_nocopy(curpkgd,
|
||||
"version", ®ver)) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
if (xbps_cmpver(version, regver) <= 0) {
|
||||
printf("W: skipping %s. %s-%s already "
|
||||
"registered.\n", filen, pkgname, regver);
|
||||
@@ -167,14 +186,24 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *file)
|
||||
* We have the dictionary now, add the required
|
||||
* objects for the index.
|
||||
*/
|
||||
prop_dictionary_set_cstring(newpkgd, "filename", filen);
|
||||
if (!prop_dictionary_set_cstring(newpkgd, "filename", filen)) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
sha256 = xbps_get_file_hash(file);
|
||||
if (sha256 == NULL) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
prop_dictionary_set_cstring(newpkgd, "filename-sha256", sha256);
|
||||
if (!prop_dictionary_set_cstring(newpkgd,
|
||||
"filename-sha256", sha256)) {
|
||||
prop_object_release(newpkgd);
|
||||
free(sha256);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
free(sha256);
|
||||
|
||||
if (stat(file, &st) == -1) {
|
||||
@@ -182,8 +211,12 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *file)
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
prop_dictionary_set_uint64(newpkgd, "filename-size",
|
||||
(uint64_t)st.st_size);
|
||||
if (!prop_dictionary_set_uint64(newpkgd, "filename-size",
|
||||
(uint64_t)st.st_size)) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Add dictionary into the index and update package count.
|
||||
*/
|
||||
@@ -199,8 +232,13 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *file)
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
prop_dictionary_set_uint64(idxdict, "total-pkgs",
|
||||
prop_array_count(pkgar));
|
||||
if (!prop_dictionary_set_uint64(idxdict, "total-pkgs",
|
||||
prop_array_count(pkgar))) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
break;
|
||||
}
|
||||
prop_object_release(newpkgd);
|
||||
printf("Registered %s-%s in package index.\n",
|
||||
pkgname, version);
|
||||
printf("\033[1A\033[K");
|
||||
|
||||
@@ -207,7 +207,12 @@ show_pkg_files_from_metadir(const char *pkgname)
|
||||
goto out;
|
||||
}
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"file", &file)) {
|
||||
prop_object_iterator_release(iter);
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
printf("%s\n", file);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
@@ -230,7 +235,12 @@ show_pkg_files_from_metadir(const char *pkgname)
|
||||
goto out;
|
||||
}
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"file", &file)) {
|
||||
prop_object_iterator_release(iter);
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
printf("%s\n", file);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
Reference in New Issue
Block a user