Support for installing pkgs from multiple repositories.
--HG-- extra : convert_revision : fc8a430e71d202aa9e7560b921669f62f1947ae1
This commit is contained in:
parent
f8d7e7f66f
commit
91f7df59cd
6 changed files with 260 additions and 152 deletions
180
lib/install.c
180
lib/install.c
|
@ -32,105 +32,105 @@
|
|||
|
||||
#include <xbps_api.h>
|
||||
|
||||
bool
|
||||
xbps_install_binary_pkg_from_repolist(prop_object_t obj, void *arg, bool *done)
|
||||
int
|
||||
xbps_install_binary_pkg(const char *pkgname, const char *destdir)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
prop_string_t oloc;
|
||||
const char *repofile, *repoloc;
|
||||
prop_array_t array;
|
||||
prop_dictionary_t repolistd, repod, pkgrd;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
char plist[PATH_MAX];
|
||||
int rv = 0;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
||||
|
||||
/* Get the location */
|
||||
repofile = prop_string_cstring_nocopy(obj);
|
||||
|
||||
/* Get string for pkg-index.plist with full path. */
|
||||
if (!xbps_append_full_path(plist, repofile, XBPS_PKGINDEX))
|
||||
return false;
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(plist);
|
||||
if (dict == NULL || prop_dictionary_count(dict) == 0)
|
||||
return false;
|
||||
|
||||
oloc = prop_dictionary_get(dict, "location-remote");
|
||||
if (oloc == NULL)
|
||||
oloc = prop_dictionary_get(dict, "location-local");
|
||||
|
||||
if (oloc && prop_object_type(oloc) == PROP_TYPE_STRING)
|
||||
repoloc = prop_string_cstring_nocopy(oloc);
|
||||
else {
|
||||
prop_object_release(dict);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("Searching in repository: %s\n", repoloc);
|
||||
rv = xbps_install_binary_pkg(dict, arg, "/home/juan/root_xbps");
|
||||
*done = true;
|
||||
prop_object_release(dict);
|
||||
|
||||
if (rv != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_install_binary_pkg(prop_dictionary_t repo, const char *pkgname,
|
||||
const char *dest)
|
||||
{
|
||||
prop_dictionary_t pkg_rdict, dict;
|
||||
prop_object_t obj;
|
||||
char dbfile[PATH_MAX];
|
||||
int rv = 0;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
if (dest) {
|
||||
if ((rv = chdir(dest)) != 0)
|
||||
if (destdir) {
|
||||
if ((rv = chdir(destdir)) != 0)
|
||||
return XBPS_PKG_ECHDIRDEST;
|
||||
}
|
||||
|
||||
/* Get pkg metadata from a repository */
|
||||
pkg_rdict = xbps_find_pkg_in_dict(repo, pkgname);
|
||||
if (pkg_rdict == NULL)
|
||||
return XBPS_PKG_ENOTINREPO;
|
||||
|
||||
/* Check if package is already installed. */
|
||||
if (!xbps_append_full_path(dbfile, NULL, XBPS_REGPKGDB))
|
||||
/* Get the dictionary with list of repositories. */
|
||||
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST))
|
||||
return EINVAL;
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(dbfile);
|
||||
if (dict && xbps_find_pkg_in_dict(dict, pkgname)) {
|
||||
prop_object_release(dict);
|
||||
return XBPS_PKG_EEXIST;
|
||||
repolistd = prop_dictionary_internalize_from_file(plist);
|
||||
if (repolistd == NULL)
|
||||
return EINVAL;
|
||||
|
||||
/* Iterate over the list of repositories to find a pkg. */
|
||||
array = prop_dictionary_get(repolistd, "repository-list");
|
||||
if (array == NULL || prop_array_count(array) == 0) {
|
||||
prop_object_release(repolistd);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
obj = prop_dictionary_get(pkg_rdict, "version");
|
||||
printf("Available package: %s-%s.\n",
|
||||
pkgname, prop_string_cstring_nocopy(obj));
|
||||
(void)fflush(stdout);
|
||||
iter = prop_array_iterator(array);
|
||||
if (iter == NULL) {
|
||||
prop_object_release(repolistd);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
/*
|
||||
* Install the package, and its dependencies if there are.
|
||||
*/
|
||||
switch (xbps_install_pkg_deps(repo, pkg_rdict)) {
|
||||
case -1:
|
||||
return XBPS_PKG_EINDEPS;
|
||||
case 0:
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
/*
|
||||
* Package has no dependencies, just install it.
|
||||
* Get the dictionary from a repository's index file.
|
||||
*/
|
||||
rv = xbps_unpack_binary_pkg(pkg_rdict, xbps_unpack_archive_cb);
|
||||
break;
|
||||
case 1:
|
||||
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
||||
memset(plist, 0, sizeof(&plist));
|
||||
if (!xbps_append_full_path(plist,
|
||||
prop_string_cstring_nocopy(obj), XBPS_PKGINDEX)) {
|
||||
prop_object_iterator_release(iter);
|
||||
prop_object_release(repolistd);
|
||||
return EINVAL;
|
||||
}
|
||||
repod = prop_dictionary_internalize_from_file(plist);
|
||||
if (repod == NULL) {
|
||||
prop_object_iterator_release(iter);
|
||||
prop_object_release(repolistd);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1 means that package has dependencies, but
|
||||
* xbps_install_pkg_deps() takes care of it.
|
||||
* Get the package dictionary from current repository.
|
||||
*/
|
||||
pkgrd = xbps_find_pkg_in_dict(repod, pkgname);
|
||||
if (pkgrd == NULL) {
|
||||
prop_object_release(repod);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if pkg needs deps.
|
||||
*/
|
||||
if (!xbps_pkg_has_rundeps(pkgrd)) {
|
||||
/* pkg has no deps, just install it. */
|
||||
rv = xbps_unpack_binary_pkg(repod, pkgrd,
|
||||
xbps_unpack_archive_cb);
|
||||
prop_object_release(repolistd);
|
||||
prop_object_release(repod);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Install all required dependencies.
|
||||
*/
|
||||
rv = xbps_install_pkg_deps(array, pkgrd);
|
||||
if (rv != 0) {
|
||||
prop_object_release(repolistd);
|
||||
prop_object_release(repod);
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Finally install the package, now that all
|
||||
* required dependencies were installed.
|
||||
*/
|
||||
rv = xbps_unpack_binary_pkg(repod, pkgrd,
|
||||
xbps_unpack_archive_cb);
|
||||
prop_object_release(repolistd);
|
||||
prop_object_release(repod);
|
||||
break;
|
||||
}
|
||||
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -138,10 +138,14 @@ int
|
|||
xbps_unpack_archive_cb(struct archive *ar)
|
||||
{
|
||||
struct archive_entry *entry;
|
||||
static bool first;
|
||||
int rv = 0;
|
||||
|
||||
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
||||
if ((rv = archive_read_extract(ar, entry, 0)) != 0) {
|
||||
if (!first)
|
||||
printf("\n");
|
||||
first = true;
|
||||
printf("couldn't write %s (%s), ignoring!\n",
|
||||
archive_entry_pathname(entry), strerror(errno));
|
||||
}
|
||||
|
@ -152,9 +156,10 @@ xbps_unpack_archive_cb(struct archive *ar)
|
|||
}
|
||||
|
||||
int
|
||||
xbps_unpack_binary_pkg(prop_dictionary_t pkg, int (*cb)(struct archive *))
|
||||
xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
|
||||
int (*cb)(struct archive *))
|
||||
{
|
||||
prop_string_t pkgname, version, filename;
|
||||
prop_string_t pkgname, version, filename, repoloc;
|
||||
struct archive *ar;
|
||||
char binfile[PATH_MAX];
|
||||
int rv;
|
||||
|
@ -163,14 +168,19 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg, int (*cb)(struct archive *))
|
|||
|
||||
/* Append filename to the full path for binary pkg */
|
||||
filename = prop_dictionary_get(pkg, "filename");
|
||||
if (!xbps_append_full_path(binfile, "/storage/xbps/binpkgs",
|
||||
repoloc = prop_dictionary_get(repo, "location-local");
|
||||
|
||||
if (!xbps_append_full_path(binfile,
|
||||
prop_string_cstring_nocopy(repoloc),
|
||||
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)... ",
|
||||
printf("From repository %s ...\n",
|
||||
prop_string_cstring_nocopy(repoloc));
|
||||
printf(" Unpacking %s-%s (%s) ... ",
|
||||
prop_string_cstring_nocopy(pkgname),
|
||||
prop_string_cstring_nocopy(version),
|
||||
prop_string_cstring_nocopy(filename));
|
||||
|
@ -190,8 +200,10 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg, int (*cb)(struct archive *))
|
|||
return rv;
|
||||
}
|
||||
|
||||
if ((rv = (*cb)(ar)) == 0)
|
||||
if ((rv = (*cb)(ar)) == 0) {
|
||||
printf("done.\n");
|
||||
(void)fflush(stdout);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue