xbps-bin/install.c: use only a function for install/update/autoupdate.
--HG-- extra : convert_revision : xtraeme%40gmail.com-20091016153732-gbcr30fahvveu2u9
This commit is contained in:
parent
cb1f10d415
commit
f7689695d1
@ -26,10 +26,9 @@
|
|||||||
#ifndef _XBPS_BIN_DEFS_H_
|
#ifndef _XBPS_BIN_DEFS_H_
|
||||||
#define _XBPS_BIN_DEFS_H_
|
#define _XBPS_BIN_DEFS_H_
|
||||||
|
|
||||||
void xbps_install_pkg(const char *, bool, bool);
|
void xbps_exec_transaction(const char *, bool, bool);
|
||||||
void xbps_autoremove_pkgs(void);
|
void xbps_autoremove_pkgs(void);
|
||||||
void xbps_remove_installed_pkg(const char *, bool);
|
void xbps_remove_installed_pkg(const char *, bool);
|
||||||
void xbps_autoupdate_pkgs(bool);
|
|
||||||
int xbps_check_pkg_integrity(const char *);
|
int xbps_check_pkg_integrity(const char *);
|
||||||
int xbps_check_pkg_integrity_all(void);
|
int xbps_check_pkg_integrity_all(void);
|
||||||
int xbps_show_pkg_deps(const char *);
|
int xbps_show_pkg_deps(const char *);
|
||||||
|
@ -207,27 +207,46 @@ show_transaction_sizes(prop_object_iterator_t iter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xbps_install_pkg(const char *pkg, bool force, bool update)
|
xbps_exec_transaction(const char *pkgname, bool force, bool update)
|
||||||
{
|
{
|
||||||
struct transaction *trans;
|
struct transaction *trans;
|
||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t pkgd;
|
||||||
prop_array_t array;
|
prop_array_t array;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
|
assert(pkgname != NULL);
|
||||||
|
|
||||||
|
if (update && (strcasecmp(pkgname, "all") == 0)) {
|
||||||
/*
|
/*
|
||||||
* Find all required pkgs and sort the package transaction.
|
* Update all currently installed packages, aka
|
||||||
|
* "xbps-bin autoupdate".
|
||||||
*/
|
*/
|
||||||
pkgd = xbps_find_pkg_installed_from_plist(pkg);
|
printf("Finding new packages...\n");
|
||||||
|
if ((rv = xbps_find_new_packages()) != 0) {
|
||||||
|
if (rv == ENOENT) {
|
||||||
|
printf("No packages currently registered.\n");
|
||||||
|
cleanup(0);
|
||||||
|
}
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pkgd = xbps_find_pkg_installed_from_plist(pkgname);
|
||||||
if (update) {
|
if (update) {
|
||||||
|
/*
|
||||||
|
* Update a single package, aka
|
||||||
|
* "xbps-bin update pkgname"
|
||||||
|
*/
|
||||||
|
printf("Finding new '%s' package...\n", pkgname);
|
||||||
if (pkgd) {
|
if (pkgd) {
|
||||||
rv = xbps_find_new_pkg(pkg, pkgd);
|
rv = xbps_find_new_pkg(pkgname, pkgd);
|
||||||
if (rv == EEXIST) {
|
if (rv == EEXIST) {
|
||||||
printf("Package '%s' is up to date.\n", pkg);
|
printf("Package '%s' is up to date.\n",
|
||||||
|
pkgname);
|
||||||
prop_object_release(pkgd);
|
prop_object_release(pkgd);
|
||||||
cleanup(rv);
|
cleanup(rv);
|
||||||
} else if (rv == ENOENT) {
|
} else if (rv == ENOENT) {
|
||||||
printf("Package '%s' not found in "
|
printf("Package '%s' not found in "
|
||||||
"repository pool.\n", pkg);
|
"repository pool.\n", pkgname);
|
||||||
prop_object_release(pkgd);
|
prop_object_release(pkgd);
|
||||||
cleanup(rv);
|
cleanup(rv);
|
||||||
} else if (rv != 0) {
|
} else if (rv != 0) {
|
||||||
@ -236,25 +255,32 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
|
|||||||
}
|
}
|
||||||
prop_object_release(pkgd);
|
prop_object_release(pkgd);
|
||||||
} else {
|
} else {
|
||||||
printf("Package '%s' not installed.\n", pkg);
|
printf("Package '%s' not installed.\n",
|
||||||
|
pkgname);
|
||||||
cleanup(rv);
|
cleanup(rv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
/*
|
||||||
|
* Install a single package, aka
|
||||||
|
* "xbps-bin install pkgname"
|
||||||
|
*/
|
||||||
if (pkgd) {
|
if (pkgd) {
|
||||||
printf("Package '%s' is already installed.\n", pkg);
|
printf("Package '%s' is already installed.\n",
|
||||||
|
pkgname);
|
||||||
prop_object_release(pkgd);
|
prop_object_release(pkgd);
|
||||||
cleanup(rv);
|
cleanup(rv);
|
||||||
}
|
}
|
||||||
rv = xbps_prepare_pkg(pkg);
|
rv = xbps_prepare_pkg(pkgname);
|
||||||
if (rv != 0 && rv == EAGAIN) {
|
if (rv != 0 && rv == EAGAIN) {
|
||||||
printf("Unable to locate '%s' in repository pool.\n",
|
printf("Unable to locate '%s' in "
|
||||||
pkg);
|
"repository pool.\n", pkgname);
|
||||||
cleanup(rv);
|
cleanup(rv);
|
||||||
} else if (rv != 0 && rv != ENOENT) {
|
} else if (rv != 0 && rv != ENOENT) {
|
||||||
printf("Unexpected error: %s", strerror(rv));
|
printf("Unexpected error: %s", strerror(rv));
|
||||||
cleanup(rv);
|
cleanup(rv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
trans = calloc(1, sizeof(struct transaction));
|
trans = calloc(1, sizeof(struct transaction));
|
||||||
if (trans == NULL)
|
if (trans == NULL)
|
||||||
@ -271,7 +297,7 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
|
|||||||
*/
|
*/
|
||||||
array = prop_dictionary_get(trans->dict, "missing_deps");
|
array = prop_dictionary_get(trans->dict, "missing_deps");
|
||||||
if (prop_array_count(array) > 0) {
|
if (prop_array_count(array) > 0) {
|
||||||
show_missing_deps(trans->dict, pkg);
|
show_missing_deps(trans->dict, pkgname);
|
||||||
goto out2;
|
goto out2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,73 +483,6 @@ exec_transaction(struct transaction *trans)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
xbps_autoupdate_pkgs(bool force)
|
|
||||||
{
|
|
||||||
struct transaction *trans;
|
|
||||||
int rv = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Find new package versions.
|
|
||||||
*/
|
|
||||||
if ((rv = xbps_find_new_packages()) != 0) {
|
|
||||||
if (rv == ENOENT) {
|
|
||||||
printf("No packages currently registered.\n");
|
|
||||||
cleanup(0);
|
|
||||||
}
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Prepare transaction data.
|
|
||||||
*/
|
|
||||||
trans = calloc(1, sizeof(struct transaction));
|
|
||||||
if (trans == NULL)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get package transaction dictionary.
|
|
||||||
*/
|
|
||||||
trans->dict = xbps_get_pkg_props();
|
|
||||||
if (trans->dict == NULL) {
|
|
||||||
if (errno == 0) {
|
|
||||||
printf("All packages are up-to-date.\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
printf("Error while checking for new pkgs: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
goto out1;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Sort the package transaction dictionary.
|
|
||||||
*/
|
|
||||||
if ((rv = xbps_sort_pkg_deps(trans->dict)) != 0) {
|
|
||||||
printf("Error while sorting packages: %s\n",
|
|
||||||
strerror(rv));
|
|
||||||
goto out2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* It's time to run the transaction!
|
|
||||||
*/
|
|
||||||
trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages");
|
|
||||||
if (trans->iter == NULL) {
|
|
||||||
printf("error: allocating array mem! (%s)\n", strerror(errno));
|
|
||||||
goto out2;
|
|
||||||
}
|
|
||||||
|
|
||||||
trans->force = force;
|
|
||||||
rv = exec_transaction(trans);
|
|
||||||
|
|
||||||
prop_object_iterator_release(trans->iter);
|
|
||||||
out2:
|
|
||||||
prop_object_release(trans->dict);
|
|
||||||
out1:
|
|
||||||
free(trans);
|
|
||||||
out:
|
|
||||||
cleanup(rv);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cleanup(int rv)
|
cleanup(int rv)
|
||||||
{
|
{
|
||||||
|
@ -152,14 +152,14 @@ main(int argc, char **argv)
|
|||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
xbps_install_pkg(argv[1], force, false);
|
xbps_exec_transaction(argv[1], force, false);
|
||||||
|
|
||||||
} else if (strcasecmp(argv[0], "update") == 0) {
|
} else if (strcasecmp(argv[0], "update") == 0) {
|
||||||
/* Update an installed package. */
|
/* Update an installed package. */
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
xbps_install_pkg(argv[1], force, true);
|
xbps_exec_transaction(argv[1], force, true);
|
||||||
|
|
||||||
} else if (strcasecmp(argv[0], "remove") == 0) {
|
} else if (strcasecmp(argv[0], "remove") == 0) {
|
||||||
/* Removes a binary package. */
|
/* Removes a binary package. */
|
||||||
@ -207,7 +207,7 @@ main(int argc, char **argv)
|
|||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
xbps_autoupdate_pkgs(force);
|
xbps_exec_transaction("all", force, true);
|
||||||
|
|
||||||
} else if (strcasecmp(argv[0], "autoremove") == 0) {
|
} else if (strcasecmp(argv[0], "autoremove") == 0) {
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user