Working dependency handling for binary packages.

--HG--
extra : convert_revision : d0ff56b524efba53b11b7635972b03feaaeb889a
This commit is contained in:
Juan RP 2008-12-24 10:58:19 +01:00
parent fa3b59b246
commit 4101025318
7 changed files with 127 additions and 86 deletions

View file

@ -273,9 +273,27 @@ main(int argc, char **argv)
if (argc != 3) if (argc != 3)
usage(); usage();
rv = xbps_install_binary_pkg(argv[2], "/home/juan/root_xbps"); #if 0
dict = getrepolist_dict();
if (!xbps_callback_array_iter_in_dict(dict, "repository-list",
xbps_install_binary_pkg_from_repolist, argv[2])) {
prop_object_release(dict);
printf("ERROR: unable to find a binary package "
"for %s.\n", argv[2]);
exit(EINVAL);
}
#endif
dict = prop_dictionary_internalize_from_file("/storage/xbps/binpkgs/pkg-index.plist");
if (dict == NULL)
exit(EINVAL);
rv = xbps_install_binary_pkg(dict, argv[2],
"/home/juan/root_xbps");
if (rv) if (rv)
exit(rv); exit(rv);
prop_object_release(dict);
} else { } else {
usage(); usage();
} }

View file

@ -150,9 +150,6 @@ bool xbps_remove_string_from_array(prop_object_t, void *, bool *);
bool xbps_show_pkg_info_from_repolist(prop_object_t obj, void *, bool *); bool xbps_show_pkg_info_from_repolist(prop_object_t obj, void *, bool *);
bool xbps_show_pkg_namedesc(prop_object_t, void *, bool *); bool xbps_show_pkg_namedesc(prop_object_t, void *, bool *);
bool xbps_search_string_in_pkgs(prop_object_t, void *, bool *); bool xbps_search_string_in_pkgs(prop_object_t, void *, bool *);
int xbps_install_binary_pkg(const char *, const char *);
int xbps_unpack_binary_pkg(const char *, int (*cb)(struct archive *));
int xbps_check_reqdeps_in_pkg(const char *, prop_dictionary_t);
/* Utils */ /* Utils */
bool xbps_append_full_path(char *, const char *, const char *); bool xbps_append_full_path(char *, const char *, const char *);
@ -161,5 +158,10 @@ int xbps_cmpver_packages(const char *, const char *);
int xbps_cmpver_versions(const char *, const char *); int xbps_cmpver_versions(const char *, const char *);
const char * xbps_get_pkg_version(const char *); const char * xbps_get_pkg_version(const char *);
char * xbps_get_pkg_name(const char *); char * xbps_get_pkg_name(const char *);
int xbps_install_pkg_deps(prop_dictionary_t, prop_dictionary_t);
int xbps_install_binary_pkg(prop_dictionary_t, const char *,
const char *);
int xbps_unpack_binary_pkg(prop_dictionary_t, int (*cb)(struct archive *));
int xbps_unpack_archive_cb(struct archive *);
#endif /* !_XBPS_PLIST_H_ */ #endif /* !_XBPS_PLIST_H_ */

View file

@ -28,6 +28,7 @@
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
#define NDEBUG
#include <assert.h> #include <assert.h>
#include <prop/proplib.h> #include <prop/proplib.h>

View file

@ -97,11 +97,13 @@ xbps_add_pkg_dependency(const char *pkgname, prop_dictionary_t dict)
len = strlen(pkgname) + 1; len = strlen(pkgname) + 1;
dep->name = malloc(len); dep->name = malloc(len);
if (dep->name == NULL) if (dep->name == NULL) {
free(dep);
return; return;
}
memcpy(dep->name, pkgname, len); memcpy(dep->name, pkgname, len - 1);
dep->name[len + 1] = '\0'; dep->name[len - 1] = '\0';
dep->dict = prop_dictionary_copy(dict); dep->dict = prop_dictionary_copy(dict);
LIST_INSERT_HEAD(&pkg_deps_list, dep, deps); LIST_INSERT_HEAD(&pkg_deps_list, dep, deps);
@ -122,12 +124,13 @@ pkg_has_rundeps(prop_dictionary_t pkg)
} }
static int static int
find_deps_in_pkg(const char *plist, prop_dictionary_t pkg) find_deps_in_pkg(prop_dictionary_t repo, prop_dictionary_t pkg)
{ {
prop_dictionary_t pkgdict; prop_dictionary_t pkgdict;
prop_array_t array; prop_array_t array;
prop_string_t name;
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter = NULL;
const char *reqpkg; const char *reqpkg;
char *pkgname; char *pkgname;
@ -139,25 +142,24 @@ find_deps_in_pkg(const char *plist, prop_dictionary_t pkg)
if (iter == NULL) if (iter == NULL)
return -1; return -1;
name = prop_dictionary_get(pkg, "pkgname");
xbps_add_pkg_dependency(prop_string_cstring_nocopy(name), pkg);
/* Iterate over the list of required run dependencies for a pkg */ /* Iterate over the list of required run dependencies for a pkg */
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);
pkgname = xbps_get_pkg_name(reqpkg); pkgname = xbps_get_pkg_name(reqpkg);
pkgdict = xbps_find_pkg_from_plist(plist, pkgname); pkgdict = xbps_find_pkg_in_dict(repo, pkgname);
xbps_add_pkg_dependency(pkgname, pkgdict); xbps_add_pkg_dependency(pkgname, pkgdict);
free(pkgname); free(pkgname);
/* Iterate on required pkg to find more deps */ /* Iterate on required pkg to find more deps */
if (pkg_has_rundeps(pkgdict)) { if (pkg_has_rundeps(pkgdict)) {
/* more deps? */ /* more deps? */
prop_object_iterator_release(iter); if (!find_deps_in_pkg(repo, pkgdict))
if (!find_deps_in_pkg(plist, pkgdict)) { continue;
prop_object_release(pkgdict);
return 0;
} }
} }
prop_object_release(pkgdict);
}
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
@ -165,30 +167,47 @@ find_deps_in_pkg(const char *plist, prop_dictionary_t pkg)
} }
int int
xbps_check_reqdeps_in_pkg(const char *plist, prop_dictionary_t pkg) xbps_install_pkg_deps(prop_dictionary_t repo, prop_dictionary_t pkg)
{ {
char repolist[PATH_MAX]; pkg_dep_t *dep;
prop_string_t pkgname, version;
int rv = 0;
assert(pkg != NULL); assert(pkg != NULL);
assert(repo != NULL);
assert(prop_object_type(pkg) == PROP_TYPE_DICTIONARY); assert(prop_object_type(pkg) == PROP_TYPE_DICTIONARY);
assert(prop_dictionary_count(pkg) != 0); assert(prop_object_type(repo) == PROP_TYPE_DICTIONARY);
assert(plist != NULL);
if (!pkg_has_rundeps(pkg)) { if (!pkg_has_rundeps(pkg)) {
/* Package has no required rundeps */ /* Package has no required dependencies. */
return 0; return 0;
} }
if (!xbps_append_full_path(repolist, /* Check what dependencies are required. */
"/storage/xbps/binpkgs", XBPS_PKGINDEX)) { if (find_deps_in_pkg(repo, pkg) == -1) {
errno = ENOENT;
return -1;
}
if (find_deps_in_pkg(repolist, pkg) == -1) {
errno = XBPS_PKG_EINDEPS; errno = XBPS_PKG_EINDEPS;
return -1; return -1;
} }
/*
* Iterate over the list of dependencies and install them.
*/
LIST_FOREACH(dep, &pkg_deps_list, deps) {
pkgname = prop_dictionary_get(dep->dict, "pkgname");
version = prop_dictionary_get(dep->dict, "version");
printf("Required package: %s >= %s\n",
prop_string_cstring_nocopy(pkgname),
prop_string_cstring_nocopy(version));
(void)fflush(stdout);
rv = xbps_unpack_binary_pkg(dep->dict, xbps_unpack_archive_cb);
if (rv != 0)
break;
LIST_REMOVE(dep, deps);
free(dep->name);
prop_object_release(dep->dict);
}
return 1; return 1;
} }

View file

@ -32,15 +32,13 @@
#include <xbps_api.h> #include <xbps_api.h>
static int unpack_archive_cb(struct archive *);
int int
xbps_install_binary_pkg(const char *pkgname, const char *dest) xbps_install_binary_pkg(prop_dictionary_t repo, const char *pkgname,
const char *dest)
{ {
prop_dictionary_t repo_dict, pkg_rdict, dict; prop_dictionary_t pkg_rdict, dict;
prop_object_t obj; prop_object_t obj;
const char *repo = "/storage/xbps/binpkgs/pkg-index.plist"; char dbfile[PATH_MAX];
char dbfile[PATH_MAX], binfile[PATH_MAX];
int rv = 0; int rv = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
@ -50,70 +48,50 @@ xbps_install_binary_pkg(const char *pkgname, const char *dest)
} }
/* Get pkg metadata from a repository */ /* Get pkg metadata from a repository */
repo_dict = prop_dictionary_internalize_from_file(repo); pkg_rdict = xbps_find_pkg_in_dict(repo, pkgname);
if (repo_dict == NULL) if (pkg_rdict == NULL)
return -1;
pkg_rdict = xbps_find_pkg_in_dict(repo_dict, pkgname);
if (pkg_rdict == NULL) {
prop_object_release(repo_dict);
return XBPS_PKG_ENOTINREPO; return XBPS_PKG_ENOTINREPO;
}
if (!xbps_append_full_path(dbfile, NULL, XBPS_REGPKGDB)) {
prop_object_release(repo_dict);
return EINVAL;
}
/* Check if package is already installed. */ /* Check if package is already installed. */
if (!xbps_append_full_path(dbfile, NULL, XBPS_REGPKGDB))
return EINVAL;
dict = prop_dictionary_internalize_from_file(dbfile); dict = prop_dictionary_internalize_from_file(dbfile);
if (dict && xbps_find_pkg_in_dict(dict, pkgname)) { if (dict && xbps_find_pkg_in_dict(dict, pkgname)) {
prop_object_release(repo_dict);
prop_object_release(dict); prop_object_release(dict);
return XBPS_PKG_EEXIST; return XBPS_PKG_EEXIST;
} }
/* Append filename to the full path for binary pkg */
obj = prop_dictionary_get(pkg_rdict, "filename");
if (!xbps_append_full_path(binfile, "/storage/xbps/binpkgs",
prop_string_cstring_nocopy(obj))) {
prop_object_release(repo_dict);
return EINVAL;
}
obj = prop_dictionary_get(pkg_rdict, "version"); obj = prop_dictionary_get(pkg_rdict, "version");
printf("=> Found package: %s-%s.", printf("Available package: %s-%s.\n",
pkgname, prop_string_cstring_nocopy(obj)); pkgname, prop_string_cstring_nocopy(obj));
printf("\n");
(void)fflush(stdout);
printf("==> Checking dependencies... ");
(void)fflush(stdout); (void)fflush(stdout);
/* Looks like it's not, check dependencies and install */ /*
switch (xbps_check_reqdeps_in_pkg(dbfile, pkg_rdict)) { * Install the package, and its dependencies if there are.
*/
switch (xbps_install_pkg_deps(repo, pkg_rdict)) {
case -1: case -1:
/* There was an error checking pkg deps */
prop_object_release(repo_dict);
printf("error, exiting!\n");
fflush(stdout);
return XBPS_PKG_EINDEPS; return XBPS_PKG_EINDEPS;
case 0: case 0:
/* Package has no deps, just install it */ /*
printf("none, unpacking... "); * Package has no dependencies, just install it.
(void)fflush(stdout); */
rv = xbps_unpack_binary_pkg(binfile, unpack_archive_cb); rv = xbps_unpack_binary_pkg(pkg_rdict, xbps_unpack_archive_cb);
break; break;
case 1: case 1:
/* Package needs deps */ /*
* 1 means that package has dependencies, but
* xbps_install_pkg_deps() takes care of it.
*/
break; break;
} }
prop_object_release(repo_dict);
return rv; return rv;
} }
static int int
unpack_archive_cb(struct archive *ar) xbps_unpack_archive_cb(struct archive *ar)
{ {
struct archive_entry *entry; struct archive_entry *entry;
int rv = 0; int rv = 0;
@ -125,18 +103,35 @@ unpack_archive_cb(struct archive *ar)
} }
} }
printf("done.\n");
archive_read_finish(ar); archive_read_finish(ar);
return rv; return rv;
} }
int int
xbps_unpack_binary_pkg(const char *filename, int (*cb)(struct archive *)) xbps_unpack_binary_pkg(prop_dictionary_t pkg, int (*cb)(struct archive *))
{ {
prop_string_t pkgname, version, filename;
struct archive *ar; struct archive *ar;
char binfile[PATH_MAX];
int rv; int rv;
assert(filename != NULL); assert(pkg != NULL);
/* Append filename to the full path for binary pkg */
filename = prop_dictionary_get(pkg, "filename");
if (!xbps_append_full_path(binfile, "/storage/xbps/binpkgs",
prop_string_cstring_nocopy(filename)))
return EINVAL;
pkgname = prop_dictionary_get(pkg, "pkgname");
version = prop_dictionary_get(pkg, "version");
printf("Unpacking %s-%s (from %s)... ",
prop_string_cstring_nocopy(pkgname),
prop_string_cstring_nocopy(version),
prop_string_cstring_nocopy(filename));
(void)fflush(stdout);
ar = archive_read_new(); ar = archive_read_new();
if (ar == NULL) if (ar == NULL)
@ -146,10 +141,13 @@ xbps_unpack_binary_pkg(const char *filename, int (*cb)(struct archive *))
archive_read_support_compression_all(ar); archive_read_support_compression_all(ar);
archive_read_support_format_all(ar); archive_read_support_format_all(ar);
if ((rv = archive_read_open_filename(ar, filename, 2048)) != 0) { if ((rv = archive_read_open_filename(ar, binfile, 2048)) != 0) {
archive_read_finish(ar); archive_read_finish(ar);
return rv; return rv;
} }
return (*cb)(ar); if ((rv = (*cb)(ar)) == 0)
printf("done.\n");
return rv;
} }

View file

@ -99,7 +99,7 @@ prop_dictionary_t
xbps_find_pkg_from_plist(const char *plist, const char *pkgname) xbps_find_pkg_from_plist(const char *plist, const char *pkgname)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
prop_dictionary_t obj; prop_dictionary_t obj, res;
assert(plist != NULL); assert(plist != NULL);
assert(pkgname != NULL); assert(pkgname != NULL);
@ -117,7 +117,10 @@ xbps_find_pkg_from_plist(const char *plist, const char *pkgname)
return NULL; return NULL;
} }
return obj; res = prop_dictionary_copy(obj);
prop_object_release(dict);
return res;
} }
prop_dictionary_t prop_dictionary_t

View file

@ -6,4 +6,4 @@ LIBDIR ?= $(PREFIX)/lib
CPPFLAGS += -I../include CPPFLAGS += -I../include
CFLAGS += -Wstack-protector -fstack-protector-all CFLAGS += -Wstack-protector -fstack-protector-all
CFLAGS += -ggdb -O2 -Wall -Werror -fPIC -DPIC CFLAGS += -O2 -Wall -Werror -fPIC -DPIC