Introduce xbps_transaction_remove_pkg() and use it for xbps-bin(8).
This commit is contained in:
@@ -2,7 +2,7 @@ TOPDIR = ../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
BIN = xbps-bin
|
||||
OBJS = transaction.o main.o remove.o show-deps.o
|
||||
OBJS = transaction.o main.o show-deps.o
|
||||
OBJS += show-info-files.o util.o find-files.o
|
||||
OBJS += question.o fetch_cb.o state_cb.o
|
||||
OBJS += check.o check_pkg_automatic.o check_pkg_files.o
|
||||
|
||||
@@ -46,6 +46,7 @@ struct list_pkgver_cb {
|
||||
/* from transaction.c */
|
||||
int install_new_pkg(const char *);
|
||||
int update_pkg(const char *);
|
||||
int remove_pkg(const char *, bool, bool);
|
||||
int autoupdate_pkgs(bool, bool);
|
||||
int autoremove_pkgs(bool, bool);
|
||||
int exec_transaction(bool, bool);
|
||||
|
||||
@@ -62,18 +62,22 @@ cleanup(int signum)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
prop_array_t reqby;
|
||||
struct xbps_handle *xhp;
|
||||
struct xferstat xfer;
|
||||
struct list_pkgver_cb lpc;
|
||||
struct sigaction sa;
|
||||
const char *rootdir, *cachedir, *confdir, *option;
|
||||
int i , c, flags, rv;
|
||||
bool yes, purge, debug, force_rm_with_deps, recursive_rm;
|
||||
const char *rootdir, *cachedir, *confdir, *option, *pkgver;
|
||||
size_t x;
|
||||
int i, c, flags, rv;
|
||||
bool yes, purge, debug, reqby_force, force_rm_with_deps, recursive_rm;
|
||||
bool install_auto, install_manual, show_download_pkglist_url;
|
||||
|
||||
rootdir = cachedir = confdir = option = NULL;
|
||||
flags = rv = 0;
|
||||
yes = purge = force_rm_with_deps = recursive_rm = debug = false;
|
||||
reqby_force = yes = purge = force_rm_with_deps = false;
|
||||
recursive_rm = debug = false;
|
||||
install_auto = install_manual = show_download_pkglist_url = false;
|
||||
|
||||
while ((c = getopt(argc, argv, "AC:c:dDFfMo:pRr:Vvy")) != -1) {
|
||||
@@ -247,12 +251,39 @@ main(int argc, char **argv)
|
||||
rv = exec_transaction(yes, show_download_pkglist_url);
|
||||
|
||||
} else if (strcasecmp(argv[0], "remove") == 0) {
|
||||
/* Removes a binary package. */
|
||||
/* Removes a package. */
|
||||
if (argc < 2)
|
||||
usage(xhp);
|
||||
|
||||
rv = remove_installed_pkgs(argc, argv, yes, purge,
|
||||
force_rm_with_deps, recursive_rm);
|
||||
for (i = 1; i < argc; i++) {
|
||||
rv = remove_pkg(argv[i], purge, recursive_rm);
|
||||
if (rv == 0)
|
||||
continue;
|
||||
else if (rv != EEXIST)
|
||||
goto out;
|
||||
|
||||
/* pkg has revdeps */
|
||||
pkgd = xbps_find_pkg_dict_installed(argv[i], false);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd,
|
||||
"pkgver", &pkgver);
|
||||
reqby = prop_dictionary_get(pkgd, "requiredby");
|
||||
prop_object_release(pkgd);
|
||||
printf("WARNING: %s IS REQUIRED BY %u PACKAGE%s:\n\n",
|
||||
pkgver, prop_array_count(reqby),
|
||||
prop_array_count(reqby) > 1 ? "S" : "");
|
||||
for (x = 0; x < prop_array_count(reqby); x++) {
|
||||
prop_array_get_cstring_nocopy(reqby, x, &pkgver);
|
||||
print_package_line(pkgver, false);
|
||||
}
|
||||
printf("\n\n");
|
||||
print_package_line(NULL, true);
|
||||
reqby_force = true;
|
||||
}
|
||||
if (reqby_force && !force_rm_with_deps) {
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
rv = exec_transaction(yes, false);
|
||||
|
||||
} else if (strcasecmp(argv[0], "show") == 0) {
|
||||
/* Shows info about an installed binary package. */
|
||||
|
||||
@@ -1,174 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2011 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "defs.h"
|
||||
#include "../xbps-repo/defs.h"
|
||||
|
||||
static int
|
||||
pkg_remove_and_purge(const char *pkgname, const char *version, bool purge)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0)
|
||||
return rv;
|
||||
|
||||
if (purge)
|
||||
if ((rv = xbps_purge_pkg(pkgname, false)) != 0)
|
||||
return rv;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
remove_installed_pkgs(int argc, char **argv, bool yes, bool purge,
|
||||
bool force_rm_with_deps, bool recursive_rm)
|
||||
{
|
||||
prop_array_t sorted, unsorted, orphans, reqby, orphans_user = NULL;
|
||||
prop_dictionary_t dict;
|
||||
size_t x;
|
||||
const char *version, *pkgver, *pkgname;
|
||||
int i, rv = 0;
|
||||
bool found = false, reqby_force = false;
|
||||
|
||||
unsorted = prop_array_create();
|
||||
if (unsorted == NULL)
|
||||
return -1;
|
||||
|
||||
sorted = prop_array_create();
|
||||
if (sorted == NULL)
|
||||
return -1;
|
||||
/*
|
||||
* If recursively removing packages, find out which packages
|
||||
* would be orphans if the supplied packages were already removed.
|
||||
*/
|
||||
if (recursive_rm) {
|
||||
orphans_user = prop_array_create();
|
||||
if (orphans_user == NULL) {
|
||||
xbps_error_printf("NULL orphans_user array\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
for (x = 0, i = 1; i < argc; i++, x++)
|
||||
prop_array_set_cstring_nocopy(orphans_user, x, argv[i]);
|
||||
|
||||
orphans = xbps_find_pkg_orphans(orphans_user);
|
||||
prop_object_release(orphans_user);
|
||||
if (orphans == NULL) {
|
||||
xbps_error_printf("NULL orphans array\n");
|
||||
return EINVAL;
|
||||
}
|
||||
for (x = 0; x < prop_array_count(orphans); x++)
|
||||
prop_array_add(unsorted, prop_array_get(orphans, x));
|
||||
|
||||
prop_object_release(orphans);
|
||||
}
|
||||
/*
|
||||
* First check if package is required by other packages.
|
||||
*/
|
||||
for (i = 1; i < argc; i++) {
|
||||
dict = xbps_find_pkg_dict_installed(argv[i], false);
|
||||
if (dict == NULL) {
|
||||
printf("Package %s is not installed.\n", argv[i]);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* Check that current package is not required by
|
||||
* other installed packages.
|
||||
*/
|
||||
prop_array_add(sorted, dict);
|
||||
found = true;
|
||||
prop_dictionary_get_cstring_nocopy(dict, "pkgver", &pkgver);
|
||||
reqby = prop_dictionary_get(dict, "requiredby");
|
||||
if (reqby == NULL || prop_array_count(reqby) == 0) {
|
||||
prop_object_release(dict);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("WARNING: %s IS REQUIRED BY %u PACKAGE%s:\n\n",
|
||||
pkgver, prop_array_count(reqby),
|
||||
prop_array_count(reqby) > 1 ? "S" : "");
|
||||
for (x = 0; x < prop_array_count(reqby); x++) {
|
||||
prop_array_get_cstring_nocopy(reqby, x, &pkgver);
|
||||
print_package_line(pkgver, false);
|
||||
}
|
||||
printf("\n\n");
|
||||
print_package_line(NULL, true);
|
||||
reqby_force = true;
|
||||
prop_object_release(dict);
|
||||
}
|
||||
if (!found) {
|
||||
prop_object_release(unsorted);
|
||||
return 0;
|
||||
}
|
||||
if (reqby_force && !force_rm_with_deps) {
|
||||
prop_object_release(unsorted);
|
||||
prop_object_release(sorted);
|
||||
return EINVAL;
|
||||
}
|
||||
for (x = 0; x < prop_array_count(unsorted); x++) {
|
||||
dict = prop_array_get(unsorted, x);
|
||||
prop_array_add(sorted, dict);
|
||||
}
|
||||
prop_object_release(unsorted);
|
||||
/*
|
||||
* Show the list of going-to-be removed packages.
|
||||
*/
|
||||
printf("%u package%s will be removed%s:\n",
|
||||
prop_array_count(sorted),
|
||||
prop_array_count(sorted) == 1 ? "" : "s",
|
||||
purge ? " and purged" : "");
|
||||
|
||||
for (x = 0; x < prop_array_count(sorted); x++) {
|
||||
dict = prop_array_get(sorted, x);
|
||||
prop_dictionary_get_cstring_nocopy(dict, "pkgver", &pkgver);
|
||||
print_package_line(pkgver, false);
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
if (!yes && !noyes("Do you want to continue?")) {
|
||||
printf("Cancelling!\n");
|
||||
prop_object_release(sorted);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (x = 0; x < prop_array_count(sorted); x++) {
|
||||
dict = prop_array_get(sorted, x);
|
||||
prop_dictionary_get_cstring_nocopy(dict, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
|
||||
if ((rv = pkg_remove_and_purge(pkgname, version, purge)) != 0) {
|
||||
prop_object_release(sorted);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
prop_object_release(sorted);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ show_package_list(prop_object_iterator_t iter, const char *match)
|
||||
static int
|
||||
show_transaction_sizes(struct transaction *trans)
|
||||
{
|
||||
uint64_t dlsize = 0, instsize = 0;
|
||||
uint64_t dlsize = 0, instsize = 0, rmsize = 0;
|
||||
char size[8];
|
||||
|
||||
/*
|
||||
@@ -155,26 +155,38 @@ show_transaction_sizes(struct transaction *trans)
|
||||
show_package_list(trans->iter, "remove");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Show total download/installed size for all required packages.
|
||||
* Show total download/installed/removed size for all required packages.
|
||||
*/
|
||||
printf("\n");
|
||||
prop_dictionary_get_uint64(trans->d, "total-download-size", &dlsize);
|
||||
if (dlsize > 0) {
|
||||
if (xbps_humanize_number(size, (int64_t)dlsize) == -1) {
|
||||
xbps_error_printf("xbps-bin: error: humanize_number returns "
|
||||
"%s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
printf("Total download size:\t%6s\n", size);
|
||||
}
|
||||
prop_dictionary_get_uint64(trans->d, "total-installed-size",
|
||||
&instsize);
|
||||
if (xbps_humanize_number(size, (int64_t)dlsize) == -1) {
|
||||
xbps_error_printf("xbps-bin: error: humanize_number returns "
|
||||
"%s\n", strerror(errno));
|
||||
return -1;
|
||||
if (instsize > 0) {
|
||||
if (xbps_humanize_number(size, (int64_t)instsize) == -1) {
|
||||
xbps_error_printf("xbps-bin: error: humanize_number2 returns "
|
||||
"%s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
printf("Total installed size:\t%6s\n\n", size);
|
||||
}
|
||||
printf("\nTotal download size:\t%6s\n", size);
|
||||
if (xbps_humanize_number(size, (int64_t)instsize) == -1) {
|
||||
xbps_error_printf("xbps-bin: error: humanize_number2 returns "
|
||||
"%s\n", strerror(errno));
|
||||
return -1;
|
||||
prop_dictionary_get_uint64(trans->d, "total-removed-size", &rmsize);
|
||||
if (rmsize > 0) {
|
||||
if (xbps_humanize_number(size, (int64_t)rmsize) == -1) {
|
||||
xbps_error_printf("xbps-bin: error: humanize_number3 returns "
|
||||
"%s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
printf("Total removed size:\t%6s\n\n", size);
|
||||
}
|
||||
printf("Total installed size:\t%6s\n\n", size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -309,6 +321,26 @@ update_pkg(const char *pkgname)
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
remove_pkg(const char *pkgname, bool purge, bool recursive)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = xbps_transaction_remove_pkg(pkgname, purge, recursive);
|
||||
if (rv == EEXIST)
|
||||
return rv;
|
||||
else if (rv == ENOENT) {
|
||||
printf("Package `%s' is not currently installed.\n", pkgname);
|
||||
return 0;
|
||||
} else {
|
||||
xbps_error_printf("Failed to queue `%s' for removing: %s\n",
|
||||
pkgname, strerror(rv));
|
||||
return rv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
exec_transaction(bool yes, bool show_download_urls)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user