Improve binpkg priorities, dynamically allocate mem, etc.

--HG--
extra : convert_revision : 479011aba6e9da4e5662137381e04042e762d428
This commit is contained in:
Juan RP 2008-12-27 22:19:04 +01:00
parent 86cdb7dae6
commit 926b1dfa4a
7 changed files with 167 additions and 68 deletions

View file

@ -46,6 +46,8 @@ static prop_dictionary_t getrepolist_dict(const char *);
static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *); static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *);
static void usage(void); static void usage(void);
static char *plist;
static void static void
usage(void) usage(void)
{ {
@ -106,17 +108,18 @@ static prop_dictionary_t
getrepolist_dict(const char *root) getrepolist_dict(const char *root)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
char plist[PATH_MAX];
xbps_set_rootdir(root); xbps_set_rootdir(root);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL)
exit(1); exit(1);
dict = prop_dictionary_internalize_from_file(plist); dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) { if (dict == NULL) {
printf("ERROR: cannot find repository plist file (%s).\n", printf("ERROR: cannot find repository plist file (%s).\n",
strerror(errno)); strerror(errno));
free(plist);
exit(EINVAL); exit(EINVAL);
} }
@ -170,16 +173,14 @@ main(int argc, char **argv)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
repo_info_t *rinfo = NULL; repo_info_t *rinfo = NULL;
char dpkgidx[PATH_MAX], repolist[PATH_MAX], *root = NULL; char dpkgidx[PATH_MAX], *root = NULL;
int c, rv = 0; int c, rv = 0;
while ((c = getopt(argc, argv, "r:")) != -1) { while ((c = getopt(argc, argv, "r:")) != -1) {
switch (c) { switch (c) {
case 'r': case 'r':
/* To specify the root directory */ /* To specify the root directory */
root = strdup(optarg); root = optarg;
if (root == NULL)
exit(ENOMEM);
xbps_set_rootdir(root); xbps_set_rootdir(root);
break; break;
case '?': case '?':
@ -203,27 +204,30 @@ main(int argc, char **argv)
exit(EINVAL); exit(EINVAL);
/* Temp buffer to verify pkgindex file. */ /* Temp buffer to verify pkgindex file. */
if (!xbps_append_full_path(false, repolist, dpkgidx, plist = xbps_append_full_path(false, dpkgidx, XBPS_PKGINDEX);
XBPS_PKGINDEX)) if (plist == NULL)
exit(EINVAL); exit(EINVAL);
dict = prop_dictionary_internalize_from_file(repolist); dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) { if (dict == NULL) {
printf("Directory %s does not contain any " printf("Directory %s does not contain any "
"xbps pkgindex file.\n", dpkgidx); "xbps pkgindex file.\n", dpkgidx);
free(plist);
exit(EINVAL); exit(EINVAL);
} }
rinfo = malloc(sizeof(*rinfo)); rinfo = malloc(sizeof(*rinfo));
if (rinfo == NULL) { if (rinfo == NULL) {
prop_object_release(dict); prop_object_release(dict);
free(plist);
exit(ENOMEM); exit(ENOMEM);
} }
if (!pkgindex_getinfo(dict, rinfo)) { if (!pkgindex_getinfo(dict, rinfo)) {
printf("'%s' is incomplete.\n", repolist); printf("'%s' is incomplete.\n", plist);
prop_object_release(dict); prop_object_release(dict);
free(rinfo); free(rinfo);
free(plist);
exit(EINVAL); exit(EINVAL);
} }
@ -232,6 +236,7 @@ main(int argc, char **argv)
strerror(errno)); strerror(errno));
prop_object_release(dict); prop_object_release(dict);
free(rinfo); free(rinfo);
free(plist);
exit(EINVAL); exit(EINVAL);
} }
@ -241,6 +246,7 @@ main(int argc, char **argv)
prop_object_release(dict); prop_object_release(dict);
free(rinfo); free(rinfo);
free(plist);
} else if (strcasecmp(argv[0], "repo-list") == 0) { } else if (strcasecmp(argv[0], "repo-list") == 0) {
/* Lists all repositories registered in pool. */ /* Lists all repositories registered in pool. */
@ -251,6 +257,7 @@ main(int argc, char **argv)
(void)xbps_callback_array_iter_in_dict(dict, (void)xbps_callback_array_iter_in_dict(dict,
"repository-list", xbps_list_strings_in_array, NULL); "repository-list", xbps_list_strings_in_array, NULL);
prop_object_release(dict); prop_object_release(dict);
free(plist);
} else if (strcasecmp(argv[0], "repo-rm") == 0) { } else if (strcasecmp(argv[0], "repo-rm") == 0) {
/* Remove a repository from the pool. */ /* Remove a repository from the pool. */
@ -279,6 +286,7 @@ main(int argc, char **argv)
(void)xbps_callback_array_iter_in_dict(dict, (void)xbps_callback_array_iter_in_dict(dict,
"repository-list", xbps_search_string_in_pkgs, argv[1]); "repository-list", xbps_search_string_in_pkgs, argv[1]);
prop_object_release(dict); prop_object_release(dict);
free(plist);
} else if (strcasecmp(argv[0], "show") == 0) { } else if (strcasecmp(argv[0], "show") == 0) {
/* Shows info about a binary package. */ /* Shows info about a binary package. */
@ -289,32 +297,38 @@ main(int argc, char **argv)
if (xbps_callback_array_iter_in_dict(dict, "repository-list", if (xbps_callback_array_iter_in_dict(dict, "repository-list",
xbps_show_pkg_info_from_repolist, argv[1]) != 0) { xbps_show_pkg_info_from_repolist, argv[1]) != 0) {
prop_object_release(dict); prop_object_release(dict);
free(plist);
printf("ERROR: unable to locate package '%s'.\n", printf("ERROR: unable to locate package '%s'.\n",
argv[1]); argv[1]);
exit(EINVAL); exit(EINVAL);
} }
prop_object_release(dict); prop_object_release(dict);
free(plist);
} else if (strcasecmp(argv[0], "list") == 0) { } else if (strcasecmp(argv[0], "list") == 0) {
/* Lists packages currently registered in database. */ /* Lists packages currently registered in database. */
if (argc != 1) if (argc != 1)
usage(); usage();
if (!xbps_append_full_path(true, dpkgidx, NULL, XBPS_REGPKGDB)) plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
if (plist == NULL)
exit(EINVAL); exit(EINVAL);
dict = prop_dictionary_internalize_from_file(dpkgidx); dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) { if (dict == NULL) {
printf("No packages currently registered.\n"); printf("No packages currently registered.\n");
free(plist);
exit(0); exit(0);
} }
if (!xbps_callback_array_iter_in_dict(dict, "packages", if (!xbps_callback_array_iter_in_dict(dict, "packages",
xbps_list_pkgs_in_dict, NULL)) { xbps_list_pkgs_in_dict, NULL)) {
prop_object_release(dict); prop_object_release(dict);
free(plist);
exit(EINVAL); exit(EINVAL);
} }
prop_object_release(dict); prop_object_release(dict);
free(plist);
} else if (strcasecmp(argv[0], "install") == 0) { } else if (strcasecmp(argv[0], "install") == 0) {
/* Installs a binary package and required deps. */ /* Installs a binary package and required deps. */

View file

@ -72,7 +72,7 @@ main(int argc, char **argv)
{ {
prop_dictionary_t dbdict = NULL, pkgdict; prop_dictionary_t dbdict = NULL, pkgdict;
const char *version; const char *version;
char dbfile[PATH_MAX], *in_chroot_env, *root = NULL; char *dbfile, *in_chroot_env, *root = NULL;
bool in_chroot = false; bool in_chroot = false;
int c, rv = 0; int c, rv = 0;
@ -97,7 +97,8 @@ main(int argc, char **argv)
if (argc < 1) if (argc < 1)
usage(); usage();
if (!xbps_append_full_path(true, dbfile, NULL, XBPS_REGPKGDB)) { dbfile = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
if (dbfile == NULL) {
printf("=> ERROR: couldn't find regpkdb file (%s)\n", printf("=> ERROR: couldn't find regpkdb file (%s)\n",
strerror(errno)); strerror(errno));
exit(EINVAL); exit(EINVAL);

View file

@ -153,7 +153,7 @@ int xbps_search_string_in_pkgs(prop_object_t, void *, bool *);
/* Utils */ /* Utils */
void xbps_set_rootdir(const char *); void xbps_set_rootdir(const char *);
bool xbps_append_full_path(bool, char *, const char *, const char *); char * xbps_append_full_path(bool, const char *, const char *);
int xbps_check_is_installed_pkg(const char *); int xbps_check_is_installed_pkg(const char *);
int xbps_cmpver_packages(const char *, const char *); int xbps_cmpver_packages(const char *, const char *);
int xbps_cmpver_versions(const char *, const char *); int xbps_cmpver_versions(const char *, const char *);

View file

@ -49,12 +49,13 @@ xbps_check_is_installed_pkg(const char *pkg)
prop_dictionary_t dict, pkgdict; prop_dictionary_t dict, pkgdict;
prop_object_t obj; prop_object_t obj;
const char *reqver, *instver; const char *reqver, *instver;
char plist[PATH_MAX], *pkgname; char *plist, *pkgname;
int rv = 0; int rv = 0;
assert(pkg != NULL); assert(pkg != NULL);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REGPKGDB)) plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
if (plist == NULL)
return EINVAL; return EINVAL;
pkgname = xbps_get_pkg_name(pkg); pkgname = xbps_get_pkg_name(pkg);
@ -64,6 +65,7 @@ xbps_check_is_installed_pkg(const char *pkg)
dict = prop_dictionary_internalize_from_file(plist); dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) { if (dict == NULL) {
free(pkgname); free(pkgname);
free(plist);
return 1; /* not installed */ return 1; /* not installed */
} }
@ -71,6 +73,7 @@ xbps_check_is_installed_pkg(const char *pkg)
if (pkgdict == NULL) { if (pkgdict == NULL) {
prop_object_release(dict); prop_object_release(dict);
free(pkgname); free(pkgname);
free(plist);
return 1; /* not installed */ return 1; /* not installed */
} }
@ -85,6 +88,7 @@ xbps_check_is_installed_pkg(const char *pkg)
rv = xbps_cmpver_versions(instver, reqver) > 0 ? 1 : 0; rv = xbps_cmpver_versions(instver, reqver) > 0 ? 1 : 0;
free(pkgname); free(pkgname);
free(plist);
prop_object_release(dict); prop_object_release(dict);
return rv; return rv;
@ -137,9 +141,10 @@ xbps_add_pkg_dependency(const char *pkg, uint64_t prio, prop_dictionary_t repo)
free(pkgname); free(pkgname);
dep->repo = prop_dictionary_copy(repo); dep->repo = prop_dictionary_copy(repo);
dep->namever = pkg; dep->namever = pkg;
dep->priority = 0;
if (SIMPLEQ_EMPTY(&pkg_deps_queue)) { if (SIMPLEQ_EMPTY(&pkg_deps_queue)) {
SIMPLEQ_INSERT_HEAD(&pkg_deps_queue, dep, deps); SIMPLEQ_INSERT_TAIL(&pkg_deps_queue, dep, deps);
return; return;
} }
@ -149,9 +154,9 @@ xbps_add_pkg_dependency(const char *pkg, uint64_t prio, prop_dictionary_t repo)
*/ */
dep_prev = SIMPLEQ_FIRST(&pkg_deps_queue); dep_prev = SIMPLEQ_FIRST(&pkg_deps_queue);
if (prio > dep_prev->priority) if (prio > dep_prev->priority)
SIMPLEQ_INSERT_TAIL(&pkg_deps_queue, dep, deps);
else
SIMPLEQ_INSERT_HEAD(&pkg_deps_queue, dep, deps); SIMPLEQ_INSERT_HEAD(&pkg_deps_queue, dep, deps);
else
SIMPLEQ_INSERT_TAIL(&pkg_deps_queue, dep, deps);
} }
static int static int
@ -195,9 +200,13 @@ find_deps_in_pkg(prop_dictionary_t repo, prop_dictionary_t pkg)
* Package is on repo, add it into the list. * Package is on repo, add it into the list.
*/ */
prio_num = prop_dictionary_get(pkgdict, "priority"); prio_num = prop_dictionary_get(pkgdict, "priority");
if (prio_num == NULL) if (prio_num == NULL ||
prio = 0; prop_number_unsigned_integer_value(prio_num) == 0) {
else if (xbps_pkg_has_rundeps(pkgdict))
prio = 10;
else
prio = 20;
} else
prio = prop_number_unsigned_integer_value(prio_num); prio = prop_number_unsigned_integer_value(prio_num);
xbps_add_pkg_dependency(reqpkg, prio, repo); xbps_add_pkg_dependency(reqpkg, prio, repo);
@ -226,24 +235,29 @@ xbps_install_pkg_deps(prop_dictionary_t pkg)
struct pkg_dependency *dep; struct pkg_dependency *dep;
size_t required_deps = 0, deps_found = 0; size_t required_deps = 0, deps_found = 0;
const char *reqpkg, *version, *pkgname, *desc; const char *reqpkg, *version, *pkgname, *desc;
char plist[PATH_MAX], *namestr; char *plist, *namestr;
int rv = 0; int rv = 0;
bool dep_found = false; bool dep_found = false;
assert(pkg != NULL); assert(pkg != NULL);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL)
return EINVAL; return EINVAL;
repolistd = prop_dictionary_internalize_from_file(plist); repolistd = prop_dictionary_internalize_from_file(plist);
if (repolistd == NULL) if (repolistd == NULL) {
free(plist);
return EINVAL; return EINVAL;
}
free(plist);
array = prop_dictionary_get(repolistd, "repository-list"); array = prop_dictionary_get(repolistd, "repository-list");
assert(array != NULL); assert(array != NULL);
iter = prop_array_iterator(array); iter = prop_array_iterator(array);
if (iter == NULL) { if (iter == NULL) {
free(plist);
prop_object_release(repolistd); prop_object_release(repolistd);
return ENOMEM; return ENOMEM;
} }
@ -253,9 +267,9 @@ xbps_install_pkg_deps(prop_dictionary_t pkg)
* all required dependencies. * all required dependencies.
*/ */
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
memset(plist, 0, sizeof(&plist)); plist = xbps_append_full_path(false,
if (!xbps_append_full_path(false, plist, prop_string_cstring_nocopy(obj), XBPS_PKGINDEX);
prop_string_cstring_nocopy(obj), XBPS_PKGINDEX)) { if (plist == NULL) {
xbps_clean_pkg_depslist(); xbps_clean_pkg_depslist();
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
rv = EINVAL; rv = EINVAL;
@ -264,11 +278,13 @@ xbps_install_pkg_deps(prop_dictionary_t pkg)
repod = prop_dictionary_internalize_from_file(plist); repod = prop_dictionary_internalize_from_file(plist);
if (repod == NULL) { if (repod == NULL) {
free(plist);
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
rv = errno; rv = errno;
goto out; goto out;
} }
free(plist);
rv = find_deps_in_pkg(repod, pkg); rv = find_deps_in_pkg(repod, pkg);
if (rv == -1) { if (rv == -1) {
prop_object_release(repod); prop_object_release(repod);

View file

@ -38,26 +38,29 @@ xbps_install_binary_pkg_from_repolist(prop_object_t obj, void *arg,
{ {
prop_dictionary_t repod, pkgrd; prop_dictionary_t repod, pkgrd;
const char *pkgname = arg, *version, *desc; const char *pkgname = arg, *version, *desc;
char plist[PATH_MAX]; char *plist;
int rv = 0; int rv = 0;
/* /*
* Get the dictionary from a repository's index file. * Get the dictionary from a repository's index file.
*/ */
memset(plist, 0, sizeof(&plist)); plist = xbps_append_full_path(false,
if (!xbps_append_full_path(false, plist, prop_string_cstring_nocopy(obj), XBPS_PKGINDEX);
prop_string_cstring_nocopy(obj), XBPS_PKGINDEX)) if (plist == NULL)
return EINVAL; return EINVAL;
repod = prop_dictionary_internalize_from_file(plist); repod = prop_dictionary_internalize_from_file(plist);
if (repod == NULL) if (repod == NULL) {
free(plist);
return EINVAL; return EINVAL;
}
/* /*
* Get the package dictionary from current repository. * Get the package dictionary from current repository.
*/ */
pkgrd = xbps_find_pkg_in_dict(repod, pkgname); pkgrd = xbps_find_pkg_in_dict(repod, pkgname);
if (pkgrd == NULL) { if (pkgrd == NULL) {
free(plist);
prop_object_release(repod); prop_object_release(repod);
return XBPS_PKG_ENOTINREPO; return XBPS_PKG_ENOTINREPO;
} }
@ -79,6 +82,7 @@ xbps_install_binary_pkg_from_repolist(prop_object_t obj, void *arg,
if (rv == EEXIST) if (rv == EEXIST)
rv = 0; rv = 0;
} }
free(plist);
prop_object_release(repod); prop_object_release(repod);
*loop_done = true; *loop_done = true;
return rv; return rv;
@ -89,6 +93,7 @@ xbps_install_binary_pkg_from_repolist(prop_object_t obj, void *arg,
*/ */
rv = xbps_install_pkg_deps(pkgrd); rv = xbps_install_pkg_deps(pkgrd);
if (rv != 0) { if (rv != 0) {
free(plist);
prop_object_release(repod); prop_object_release(repod);
return rv; return rv;
} }
@ -102,6 +107,7 @@ xbps_install_binary_pkg_from_repolist(prop_object_t obj, void *arg,
if (rv == EEXIST) if (rv == EEXIST)
rv = 0; rv = 0;
} }
free(plist);
prop_object_release(repod); prop_object_release(repod);
*loop_done = true; *loop_done = true;
@ -112,7 +118,7 @@ int
xbps_install_binary_pkg(const char *pkgname, const char *destdir) xbps_install_binary_pkg(const char *pkgname, const char *destdir)
{ {
prop_dictionary_t repolistd; prop_dictionary_t repolistd;
char plist[PATH_MAX]; char *plist;
int rv = 0; int rv = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
@ -125,12 +131,15 @@ xbps_install_binary_pkg(const char *pkgname, const char *destdir)
* Get the dictionary with the list of registered * Get the dictionary with the list of registered
* repositories. * repositories.
*/ */
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL)
return EINVAL; return EINVAL;
repolistd = prop_dictionary_internalize_from_file(plist); repolistd = prop_dictionary_internalize_from_file(plist);
if (repolistd == NULL) if (repolistd == NULL) {
free(plist);
return EINVAL; return EINVAL;
}
/* /*
* Iterate over the repositories to find the binary packages * Iterate over the repositories to find the binary packages
@ -138,6 +147,8 @@ xbps_install_binary_pkg(const char *pkgname, const char *destdir)
*/ */
rv = xbps_callback_array_iter_in_dict(repolistd, "repository-list", rv = xbps_callback_array_iter_in_dict(repolistd, "repository-list",
xbps_install_binary_pkg_from_repolist, (void *)pkgname); xbps_install_binary_pkg_from_repolist, (void *)pkgname);
free(plist);
prop_object_release(repolistd); prop_object_release(repolistd);
return rv; return rv;
@ -163,25 +174,29 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
{ {
prop_dictionary_t dict, pkgd; prop_dictionary_t dict, pkgd;
prop_array_t array; prop_array_t array;
char plist[PATH_MAX]; char *plist;
int rv = 0; int rv = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
assert(version != NULL); assert(version != NULL);
assert(desc != NULL); assert(desc != NULL);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REGPKGDB)) plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
if (plist == NULL)
return EINVAL; return EINVAL;
dict = prop_dictionary_internalize_from_file(plist); dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) { if (dict == NULL) {
/* No packages registered yet. */ /* No packages registered yet. */
dict = prop_dictionary_create(); dict = prop_dictionary_create();
if (dict == NULL) if (dict == NULL) {
free(plist);
return ENOMEM; return ENOMEM;
}
array = prop_array_create(); array = prop_array_create();
if (array == NULL) { if (array == NULL) {
free(plist);
prop_object_release(dict); prop_object_release(dict);
return ENOMEM; return ENOMEM;
} }
@ -192,12 +207,14 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
prop_object_release(array); prop_object_release(array);
prop_object_release(dict); prop_object_release(dict);
prop_object_release(pkgd); prop_object_release(pkgd);
free(plist);
return EINVAL; return EINVAL;
} }
if (!xbps_add_obj_to_dict(dict, array, "packages")) { if (!xbps_add_obj_to_dict(dict, array, "packages")) {
prop_object_release(array); prop_object_release(array);
prop_object_release(dict); prop_object_release(dict);
free(plist);
return EINVAL; return EINVAL;
} }
@ -206,6 +223,7 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
pkgd = xbps_find_pkg_in_dict(dict, pkgname); pkgd = xbps_find_pkg_in_dict(dict, pkgname);
if (pkgd != NULL) { if (pkgd != NULL) {
prop_object_release(dict); prop_object_release(dict);
free(plist);
return EEXIST; return EEXIST;
} }
@ -216,6 +234,7 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
if (!xbps_add_obj_to_array(array, pkgd)) { if (!xbps_add_obj_to_array(array, pkgd)) {
prop_object_release(pkgd); prop_object_release(pkgd);
prop_object_release(dict); prop_object_release(dict);
free(plist);
return EINVAL; return EINVAL;
} }
} }
@ -225,6 +244,7 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
rv = errno; rv = errno;
prop_object_release(dict); prop_object_release(dict);
free(plist);
return rv; return rv;
} }
@ -253,6 +273,7 @@ xbps_unpack_archive_cb(struct archive *ar)
if ((rv = archive_read_extract(ar, entry, flags)) != 0) { if ((rv = archive_read_extract(ar, entry, flags)) != 0) {
printf("\ncouldn't unpack %s (%s), exiting!\n", printf("\ncouldn't unpack %s (%s), exiting!\n",
archive_entry_pathname(entry), strerror(errno)); archive_entry_pathname(entry), strerror(errno));
archive_entry_free(entry);
break; break;
} }
} }
@ -267,7 +288,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
{ {
prop_string_t pkgname, version, filename, repoloc; prop_string_t pkgname, version, filename, repoloc;
struct archive *ar; struct archive *ar;
char binfile[PATH_MAX]; char *binfile;
int rv; int rv;
assert(pkg != NULL); assert(pkg != NULL);
@ -278,9 +299,10 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
filename = prop_dictionary_get(pkg, "filename"); filename = prop_dictionary_get(pkg, "filename");
repoloc = prop_dictionary_get(repo, "location-local"); repoloc = prop_dictionary_get(repo, "location-local");
if (!xbps_append_full_path(false, binfile, binfile= xbps_append_full_path(false,
prop_string_cstring_nocopy(repoloc), prop_string_cstring_nocopy(repoloc),
prop_string_cstring_nocopy(filename))) prop_string_cstring_nocopy(filename));
if (binfile == NULL)
return EINVAL; return EINVAL;
pkgname = prop_dictionary_get(pkg, "pkgname"); pkgname = prop_dictionary_get(pkg, "pkgname");
@ -296,8 +318,10 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
(void)fflush(stdout); (void)fflush(stdout);
ar = archive_read_new(); ar = archive_read_new();
if (ar == NULL) if (ar == NULL) {
free(binfile);
return ENOMEM; return ENOMEM;
}
/* Enable support for all format and compression methods */ /* Enable support for all format and compression methods */
archive_read_support_compression_all(ar); archive_read_support_compression_all(ar);
@ -305,6 +329,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
if ((rv = archive_read_open_filename(ar, binfile, 2048)) != 0) { if ((rv = archive_read_open_filename(ar, binfile, 2048)) != 0) {
archive_read_finish(ar); archive_read_finish(ar);
free(binfile);
return rv; return rv;
} }
@ -313,5 +338,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
(void)fflush(stdout); (void)fflush(stdout);
} }
free(binfile);
return rv; return rv;
} }

View file

@ -270,11 +270,12 @@ xbps_register_repository(const char *uri)
prop_dictionary_t dict; prop_dictionary_t dict;
prop_array_t array = NULL; prop_array_t array = NULL;
prop_object_t obj; prop_object_t obj;
char plist[PATH_MAX]; char *plist;
assert(uri != NULL); assert(uri != NULL);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) { plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL) {
errno = EINVAL; errno = EINVAL;
return false; return false;
} }
@ -284,13 +285,16 @@ xbps_register_repository(const char *uri)
if (dict == NULL) { if (dict == NULL) {
/* Looks like not, create it. */ /* Looks like not, create it. */
dict = prop_dictionary_create(); dict = prop_dictionary_create();
if (dict == NULL) if (dict == NULL) {
free(plist);
return false; return false;
}
/* Create the array and add the repository URI on it. */ /* Create the array and add the repository URI on it. */
array = prop_array_create(); array = prop_array_create();
if (array == NULL) { if (array == NULL) {
prop_object_release(dict); prop_object_release(dict);
free(plist);
return false; return false;
} }
@ -306,6 +310,7 @@ xbps_register_repository(const char *uri)
goto fail; goto fail;
prop_object_release(dict); prop_object_release(dict);
} else { } else {
/* Append into the array, the plist file exists. */ /* Append into the array, the plist file exists. */
array = prop_dictionary_get(dict, "repository-list"); array = prop_dictionary_get(dict, "repository-list");
@ -332,13 +337,17 @@ xbps_register_repository(const char *uri)
return false; return false;
} }
prop_object_release(obj); prop_object_release(dict);
} }
free(plist);
return true; return true;
fail: fail:
prop_object_release(dict); prop_object_release(dict);
free(plist);
return false; return false;
} }
@ -348,23 +357,27 @@ xbps_unregister_repository(const char *uri)
prop_dictionary_t dict; prop_dictionary_t dict;
prop_array_t array; prop_array_t array;
struct callback_args *cb; struct callback_args *cb;
char plist[PATH_MAX]; char *plist;
bool done = false; bool done = false;
assert(uri != NULL); assert(uri != NULL);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) { plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
if (plist == NULL) {
errno = EINVAL; errno = EINVAL;
return false; return false;
} }
dict = prop_dictionary_internalize_from_file(plist); dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) if (dict == NULL) {
free(plist);
return false; return false;
}
array = prop_dictionary_get(dict, "repository-list"); array = prop_dictionary_get(dict, "repository-list");
if (array == NULL) { if (array == NULL) {
prop_object_release(dict); prop_object_release(dict);
free(plist);
return false; return false;
} }
@ -373,6 +386,7 @@ xbps_unregister_repository(const char *uri)
cb = malloc(sizeof(*cb)); cb = malloc(sizeof(*cb));
if (cb == NULL) { if (cb == NULL) {
prop_object_release(dict); prop_object_release(dict);
free(plist);
errno = ENOMEM; errno = ENOMEM;
return false; return false;
} }
@ -390,6 +404,7 @@ xbps_unregister_repository(const char *uri)
if (prop_dictionary_externalize_to_file(dict, plist)) { if (prop_dictionary_externalize_to_file(dict, plist)) {
free(cb); free(cb);
prop_object_release(dict); prop_object_release(dict);
free(plist);
return true; return true;
} }
} else { } else {
@ -399,6 +414,8 @@ xbps_unregister_repository(const char *uri)
prop_object_release(dict); prop_object_release(dict);
free(cb); free(cb);
free(plist);
return false; return false;
} }
@ -508,7 +525,7 @@ xbps_search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
const char *repofile; const char *repofile;
char plist[PATH_MAX]; char *plist;
assert(prop_object_type(obj) == PROP_TYPE_STRING); assert(prop_object_type(obj) == PROP_TYPE_STRING);
@ -516,17 +533,21 @@ xbps_search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done)
repofile = prop_string_cstring_nocopy(obj); repofile = prop_string_cstring_nocopy(obj);
assert(repofile != NULL); assert(repofile != NULL);
if (!xbps_append_full_path(false, plist, repofile, XBPS_PKGINDEX)) plist = xbps_append_full_path(false, repofile, XBPS_PKGINDEX);
if (plist == NULL)
return EINVAL; return EINVAL;
dict = prop_dictionary_internalize_from_file(plist); dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) if (dict == NULL) {
free(plist);
return EINVAL; return EINVAL;
}
printf("From %s repository ...\n", repofile); printf("From %s repository ...\n", repofile);
xbps_callback_array_iter_in_dict(dict, "packages", xbps_callback_array_iter_in_dict(dict, "packages",
xbps_show_pkg_namedesc, arg); xbps_show_pkg_namedesc, arg);
prop_object_release(dict); prop_object_release(dict);
free(plist);
return 0; return 0;
} }
@ -537,7 +558,7 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
prop_dictionary_t dict, pkgdict; prop_dictionary_t dict, pkgdict;
prop_string_t oloc; prop_string_t oloc;
const char *repofile, *repoloc; const char *repofile, *repoloc;
char plist[PATH_MAX]; char *plist;
assert(prop_object_type(obj) == PROP_TYPE_STRING); assert(prop_object_type(obj) == PROP_TYPE_STRING);
@ -545,16 +566,20 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
repofile = prop_string_cstring_nocopy(obj); repofile = prop_string_cstring_nocopy(obj);
/* Get string for pkg-index.plist with full path. */ /* Get string for pkg-index.plist with full path. */
if (!xbps_append_full_path(false, plist, repofile, XBPS_PKGINDEX)) plist = xbps_append_full_path(false, repofile, XBPS_PKGINDEX);
if (plist == NULL)
return EINVAL; return EINVAL;
dict = prop_dictionary_internalize_from_file(plist); dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL || prop_dictionary_count(dict) == 0) if (dict == NULL || prop_dictionary_count(dict) == 0) {
free(plist);
return EINVAL; return EINVAL;
}
pkgdict = xbps_find_pkg_in_dict(dict, arg); pkgdict = xbps_find_pkg_in_dict(dict, arg);
if (pkgdict == NULL) { if (pkgdict == NULL) {
prop_object_release(dict); prop_object_release(dict);
free(plist);
return XBPS_PKG_ENOTINREPO; return XBPS_PKG_ENOTINREPO;
} }
@ -566,6 +591,7 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
repoloc = prop_string_cstring_nocopy(oloc); repoloc = prop_string_cstring_nocopy(oloc);
else { else {
prop_object_release(dict); prop_object_release(dict);
free(plist);
return EINVAL; return EINVAL;
} }
@ -573,6 +599,7 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
xbps_show_pkg_info(pkgdict); xbps_show_pkg_info(pkgdict);
*loop_done = true; *loop_done = true;
prop_object_release(dict); prop_object_release(dict);
free(plist);
return 0; return 0;
} }

View file

@ -88,14 +88,15 @@ xbps_set_rootdir(const char *dir)
rootdir = dir; rootdir = dir;
} }
bool char *
xbps_append_full_path(bool use_rootdir, char *buf, const char *basedir, xbps_append_full_path(bool use_rootdir, const char *basedir, const char *plist)
const char *plistf)
{ {
const char *env; const char *env;
char *buf;
size_t len = 0;
assert(buf != NULL); assert(buf != NULL);
assert(plistf != NULL); assert(plist != NULL);
if (basedir) if (basedir)
env = basedir; env = basedir;
@ -103,18 +104,31 @@ xbps_append_full_path(bool use_rootdir, char *buf, const char *basedir,
env = XBPS_META_PATH; env = XBPS_META_PATH;
if (rootdir && use_rootdir) { if (rootdir && use_rootdir) {
if (snprintf(buf, PATH_MAX - 1, "%s/%s/%s", len = strlen(rootdir) + strlen(env) + strlen(plist) + 2;
rootdir, env, plistf) < 0) { buf = malloc(len + 1);
if (buf == NULL) {
errno = ENOMEM;
return NULL;
}
if (snprintf(buf, len + 1, "%s/%s/%s",
rootdir, env, plist) < 0) {
errno = ENOSPC; errno = ENOSPC;
return false; return NULL;
} }
} else { } else {
if (snprintf(buf, PATH_MAX - 1, "%s/%s", len = strlen(env) + strlen(plist) + 1;
env, plistf) < 0) { buf = malloc(len + 1);
if (buf == NULL) {
errno = ENOMEM;
return NULL;
}
if (snprintf(buf, len + 1, "%s/%s", env, plist) < 0) {
errno = ENOSPC; errno = ENOSPC;
return false; return NULL;
} }
} }
return true; return buf;
} }