2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2010-01-25 20:46:04 +05:30
|
|
|
* Copyright (c) 2008-2010 Juan Romero Pardines.
|
2009-08-17 22:37:20 +05:30
|
|
|
* 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"
|
2009-11-24 16:35:39 +05:30
|
|
|
#include "../xbps-repo/defs.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-04-28 06:56:13 +05:30
|
|
|
static int
|
|
|
|
pkg_remove_and_purge(const char *pkgname, const char *version, bool purge)
|
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
|
2010-11-06 11:14:00 +05:30
|
|
|
printf("Removing package %s-%s ...\n", pkgname, version);
|
2010-04-28 06:56:13 +05:30
|
|
|
|
|
|
|
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0) {
|
|
|
|
fprintf(stderr, "\nE: unable to remove %s-%s (%s).\n",
|
|
|
|
pkgname, version, strerror(errno));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (purge) {
|
2010-11-06 11:14:00 +05:30
|
|
|
printf(" Purging ... ");
|
2010-04-28 06:56:13 +05:30
|
|
|
(void)fflush(stdout);
|
|
|
|
if ((rv = xbps_purge_pkg(pkgname, false)) != 0) {
|
|
|
|
fprintf(stderr, "\nE: unable to purge %s-%s "
|
|
|
|
"(%s).\n", pkgname, version,
|
|
|
|
strerror(errno));
|
|
|
|
return rv;
|
|
|
|
}
|
2010-11-06 11:14:00 +05:30
|
|
|
printf("done.\n");
|
2010-04-28 06:56:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-10-23 17:31:54 +05:30
|
|
|
int
|
2010-12-03 22:06:07 +05:30
|
|
|
xbps_autoremove_pkgs(bool yes, bool purge)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2010-01-28 22:14:23 +05:30
|
|
|
prop_array_t orphans = NULL;
|
|
|
|
prop_object_t obj = NULL;
|
|
|
|
prop_object_iterator_t iter = NULL;
|
2009-11-22 09:45:47 +05:30
|
|
|
const char *pkgver, *pkgname, *version;
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Removes orphan pkgs. These packages were installed
|
|
|
|
* as dependency and any installed package does not depend
|
|
|
|
* on it currently.
|
|
|
|
*/
|
|
|
|
orphans = xbps_find_orphan_packages();
|
|
|
|
if (orphans == NULL)
|
2009-10-23 17:31:54 +05:30
|
|
|
return errno;
|
|
|
|
|
2010-01-25 20:46:04 +05:30
|
|
|
if (prop_array_count(orphans) == 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
printf("There are not orphaned packages currently.\n");
|
2009-10-23 17:31:54 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
iter = prop_array_iterator(orphans);
|
2009-10-23 17:31:54 +05:30
|
|
|
if (iter == NULL) {
|
|
|
|
rv = errno;
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
2009-10-23 17:31:54 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
printf("The following packages were installed automatically\n"
|
|
|
|
"(as dependencies) and aren't needed anymore:\n\n");
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
2010-12-03 22:06:07 +05:30
|
|
|
print_package_line(pkgver);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
printf("\n\n");
|
|
|
|
|
2010-12-03 22:06:07 +05:30
|
|
|
if (!yes && !xbps_noyes("Do you want to continue?")) {
|
2009-08-17 22:37:20 +05:30
|
|
|
printf("Cancelled!\n");
|
2010-01-25 20:46:04 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
2010-04-28 06:56:13 +05:30
|
|
|
if ((rv = pkg_remove_and_purge(pkgname, version, purge)) != 0)
|
2010-01-25 20:46:04 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-01-25 20:46:04 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
out:
|
2010-01-25 20:46:04 +05:30
|
|
|
if (iter)
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
if (orphans)
|
|
|
|
prop_object_release(orphans);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-10-23 17:31:54 +05:30
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2009-10-23 17:31:54 +05:30
|
|
|
int
|
2010-12-03 22:06:07 +05:30
|
|
|
xbps_remove_installed_pkgs(int argc, char **argv, bool yes, bool purge,
|
|
|
|
bool force_rm_with_deps)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2010-12-03 22:06:07 +05:30
|
|
|
prop_array_t sorted_pkgs;
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_array_t reqby;
|
|
|
|
prop_dictionary_t dict;
|
2010-12-03 22:06:07 +05:30
|
|
|
size_t x;
|
|
|
|
const char *version, *pkgver, *pkgname;
|
2009-12-22 17:07:36 +05:30
|
|
|
int i, rv = 0;
|
2010-12-03 22:06:07 +05:30
|
|
|
bool found = false, reqby_force = false;
|
|
|
|
|
|
|
|
sorted_pkgs = prop_array_create();
|
|
|
|
if (sorted_pkgs == NULL)
|
|
|
|
return -1;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* First check if package is required by other packages.
|
|
|
|
*/
|
2009-12-22 17:07:36 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
2010-01-21 07:40:19 +05:30
|
|
|
dict = xbps_find_pkg_dict_installed(argv[i], false);
|
2009-12-22 17:07:36 +05:30
|
|
|
if (dict == NULL) {
|
|
|
|
printf("Package %s is not installed.\n", argv[i]);
|
|
|
|
continue;
|
|
|
|
}
|
2010-12-03 22:06:07 +05:30
|
|
|
prop_array_add(sorted_pkgs, dict);
|
|
|
|
prop_dictionary_get_cstring_nocopy(dict, "pkgver", &pkgver);
|
2009-12-22 17:07:36 +05:30
|
|
|
found = true;
|
|
|
|
reqby = prop_dictionary_get(dict, "requiredby");
|
|
|
|
if (reqby != NULL && prop_array_count(reqby) > 0) {
|
2010-12-03 22:06:07 +05:30
|
|
|
printf("WARNING: %s IS REQUIRED BY %u PACKAGES!\n",
|
|
|
|
pkgver, prop_array_count(reqby));
|
2009-12-22 17:07:36 +05:30
|
|
|
reqby_force = true;
|
|
|
|
}
|
2010-11-08 06:32:35 +05:30
|
|
|
prop_object_release(dict);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-12-03 22:06:07 +05:30
|
|
|
if (!found) {
|
|
|
|
prop_object_release(sorted_pkgs);
|
2009-12-22 17:07:36 +05:30
|
|
|
return 0;
|
2010-12-03 22:06:07 +05:30
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-12-22 17:07:36 +05:30
|
|
|
/*
|
|
|
|
* Show the list of going-to-be removed packages.
|
|
|
|
*/
|
|
|
|
printf("The following packages will be removed:\n\n");
|
2010-12-03 22:06:07 +05:30
|
|
|
for (x = 0; x < prop_array_count(sorted_pkgs); x++) {
|
|
|
|
dict = prop_array_get(sorted_pkgs, x);
|
|
|
|
prop_dictionary_get_cstring_nocopy(dict, "pkgver", &pkgver);
|
|
|
|
print_package_line(pkgver);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-12-22 17:07:36 +05:30
|
|
|
printf("\n\n");
|
2010-12-03 22:06:07 +05:30
|
|
|
if (!yes && !xbps_noyes("Do you want to continue?")) {
|
2009-12-07 11:22:27 +05:30
|
|
|
printf("Cancelling!\n");
|
2010-12-03 22:06:07 +05:30
|
|
|
prop_object_release(sorted_pkgs);
|
2009-12-07 11:22:27 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2010-12-03 22:06:07 +05:30
|
|
|
if (reqby_force && !force_rm_with_deps) {
|
|
|
|
printf("\nYou haven't specified the -F flag to force removal with dependencies. The package(s)\n"
|
|
|
|
"you are going to remove are required by other installed packages, therefore\n"
|
|
|
|
"it might break packages that currently depend on them. If you are entirely sure\n"
|
|
|
|
"that's what you want, use 'xbps-bin -F remove ...' to continue with the operation.\n");
|
|
|
|
prop_object_release(sorted_pkgs);
|
|
|
|
return 0;
|
|
|
|
} else if (reqby_force && force_rm_with_deps)
|
|
|
|
printf("WARNING: Forcing removal! you've been alerted.\n");
|
2009-12-22 17:07:36 +05:30
|
|
|
|
2010-12-03 22:06:07 +05:30
|
|
|
for (x = 0; x < prop_array_count(sorted_pkgs); x++) {
|
|
|
|
dict = prop_array_get(sorted_pkgs, x);
|
|
|
|
prop_dictionary_get_cstring_nocopy(dict, "pkgname", &pkgname);
|
2009-12-22 17:07:36 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
|
2010-12-03 22:06:07 +05:30
|
|
|
if ((rv = pkg_remove_and_purge(pkgname, version, purge)) != 0) {
|
|
|
|
prop_object_release(sorted_pkgs);
|
2009-12-22 17:07:36 +05:30
|
|
|
return rv;
|
2010-12-03 22:06:07 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-12-03 22:06:07 +05:30
|
|
|
prop_object_release(sorted_pkgs);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-10-23 17:31:54 +05:30
|
|
|
return 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|