xbps-bin/check.c: simplify exit paths.

--HG--
extra : convert_revision : xtraeme%40gmail.com-20100125151533-z7ub7xlqbhg97ij2
This commit is contained in:
Juan RP 2010-01-25 16:15:33 +01:00
parent 920db08f5c
commit bf6b96c651

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
@ -139,13 +139,13 @@ xbps_check_pkg_integrity(const char *pkgname)
"E: %s: invalid %s metadata file.\n", pkgname, "E: %s: invalid %s metadata file.\n", pkgname,
XBPS_PKGPROPS); XBPS_PKGPROPS);
rv = EINVAL; rv = EINVAL;
goto out1; goto out;
} else if (prop_dictionary_count(propsd) == 0) { } else if (prop_dictionary_count(propsd) == 0) {
fprintf(stderr, fprintf(stderr,
"E: %s: incomplete %s metadata file.\n", pkgname, "E: %s: incomplete %s metadata file.\n", pkgname,
XBPS_PKGPROPS); XBPS_PKGPROPS);
rv = EINVAL; rv = EINVAL;
goto out1; goto out;
} }
/* /*
@ -155,7 +155,7 @@ xbps_check_pkg_integrity(const char *pkgname)
XBPS_META_PATH, pkgname, XBPS_PKGFILES); XBPS_META_PATH, pkgname, XBPS_PKGFILES);
if (path == NULL) { if (path == NULL) {
rv = errno; rv = errno;
goto out1; goto out;
} }
filesd = prop_dictionary_internalize_from_file(path); filesd = prop_dictionary_internalize_from_file(path);
@ -165,19 +165,19 @@ xbps_check_pkg_integrity(const char *pkgname)
"E: %s: unexistent %s metadata file.\n", pkgname, "E: %s: unexistent %s metadata file.\n", pkgname,
XBPS_PKGPROPS); XBPS_PKGPROPS);
rv = ENOENT; rv = ENOENT;
goto out1; goto out;
} else if (prop_object_type(filesd) != PROP_TYPE_DICTIONARY) { } else if (prop_object_type(filesd) != PROP_TYPE_DICTIONARY) {
fprintf(stderr, fprintf(stderr,
"E: %s: invalid %s metadata file.\n", pkgname, "E: %s: invalid %s metadata file.\n", pkgname,
XBPS_PKGFILES); XBPS_PKGFILES);
rv = EINVAL; rv = EINVAL;
goto out2; goto out;
} else if (prop_dictionary_count(filesd) == 0) { } else if (prop_dictionary_count(filesd) == 0) {
fprintf(stderr, fprintf(stderr,
"E: %s: incomplete %s metadata file.\n", pkgname, "E: %s: incomplete %s metadata file.\n", pkgname,
XBPS_PKGFILES); XBPS_PKGFILES);
rv = EINVAL; rv = EINVAL;
goto out2; goto out;
} else if (((array = prop_dictionary_get(filesd, "files")) == NULL) || } else if (((array = prop_dictionary_get(filesd, "files")) == NULL) ||
((array = prop_dictionary_get(filesd, "links")) == NULL) || ((array = prop_dictionary_get(filesd, "links")) == NULL) ||
((array = prop_dictionary_get(filesd, "dirs")) == NULL)) { ((array = prop_dictionary_get(filesd, "dirs")) == NULL)) {
@ -185,7 +185,7 @@ xbps_check_pkg_integrity(const char *pkgname)
"E: %s: incomplete %s metadata file.\n", pkgname, "E: %s: incomplete %s metadata file.\n", pkgname,
XBPS_PKGFILES); XBPS_PKGFILES);
rv = EINVAL; rv = EINVAL;
goto out2; goto out;
} }
/* /*
@ -197,28 +197,28 @@ xbps_check_pkg_integrity(const char *pkgname)
iter = xbps_get_array_iter_from_dict(filesd, "files"); iter = xbps_get_array_iter_from_dict(filesd, "files");
if (iter == NULL) { if (iter == NULL) {
rv = ENOMEM; rv = ENOMEM;
goto out2; goto out;
} }
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj, if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &file)) { "file", &file)) {
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
rv = errno; rv = errno;
goto out2; 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) {
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
rv = errno; rv = errno;
goto out2; goto out;
} }
if (!prop_dictionary_get_cstring_nocopy(obj, if (!prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256)) { "sha256", &sha256)) {
free(path); free(path);
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
rv = errno; rv = errno;
goto out2; goto out;
} }
rv = xbps_check_file_hash(path, sha256); rv = xbps_check_file_hash(path, sha256);
switch (rv) { switch (rv) {
@ -258,21 +258,21 @@ xbps_check_pkg_integrity(const char *pkgname)
iter = xbps_get_array_iter_from_dict(filesd, "conf_files"); iter = xbps_get_array_iter_from_dict(filesd, "conf_files");
if (iter == NULL) { if (iter == NULL) {
rv = ENOMEM; rv = ENOMEM;
goto out2; goto out;
} }
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj, if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &file)) { "file", &file)) {
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
rv = errno; rv = errno;
goto out2; 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) {
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
rv = ENOMEM; rv = ENOMEM;
goto out2; goto out;
} }
if ((rv = access(path, R_OK)) == -1) { if ((rv = access(path, R_OK)) == -1) {
if (errno == ENOENT) { if (errno == ENOENT) {
@ -301,14 +301,14 @@ xbps_check_pkg_integrity(const char *pkgname)
iter = xbps_get_array_iter_from_dict(propsd, "run_depends"); iter = xbps_get_array_iter_from_dict(propsd, "run_depends");
if (iter == NULL) { if (iter == NULL) {
rv = ENOMEM; rv = ENOMEM;
goto out2; goto out;
} }
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
reqpkg = prop_string_cstring_nocopy(obj); reqpkg = prop_string_cstring_nocopy(obj);
if (reqpkg == NULL) { if (reqpkg == NULL) {
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
rv = EINVAL; rv = EINVAL;
goto out2; goto out;
} }
if (xbps_check_is_installed_pkg(reqpkg) <= 0) { if (xbps_check_is_installed_pkg(reqpkg) <= 0) {
rv = ENOENT; rv = ENOENT;
@ -324,13 +324,13 @@ xbps_check_pkg_integrity(const char *pkgname)
} }
} }
out2:
prop_object_release(filesd);
out1:
prop_object_release(propsd);
out: out:
prop_object_release(pkgd); if (filesd)
prop_object_release(filesd);
if (propsd)
prop_object_release(propsd);
if (pkgd)
prop_object_release(pkgd);
if (broken) if (broken)
rv = EINVAL; rv = EINVAL;