xbps-bin: added -F flag for the remove target.
Unless it's set, packages that are dependencies of other installed packages won't be removed. This flag overrides this behaviour and forces the package removal. While being here, misc cleanups.
This commit is contained in:
@@ -61,15 +61,13 @@ pkg_remove_and_purge(const char *pkgname, const char *version, bool purge)
|
||||
}
|
||||
|
||||
int
|
||||
xbps_autoremove_pkgs(bool force, bool purge, bool only_show)
|
||||
xbps_autoremove_pkgs(bool yes, bool purge)
|
||||
{
|
||||
prop_array_t orphans = NULL;
|
||||
prop_object_t obj = NULL;
|
||||
prop_object_iterator_t iter = NULL;
|
||||
const char *pkgver, *pkgname, *version;
|
||||
size_t cols = 0;
|
||||
int rv = 0;
|
||||
bool first = false;
|
||||
|
||||
/*
|
||||
* Removes orphan pkgs. These packages were installed
|
||||
@@ -95,25 +93,12 @@ xbps_autoremove_pkgs(bool force, bool purge, bool only_show)
|
||||
"(as dependencies) and aren't needed anymore:\n\n");
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
cols += strlen(pkgver) + 4;
|
||||
if (cols <= 80) {
|
||||
if (first == false) {
|
||||
printf(" ");
|
||||
first = true;
|
||||
}
|
||||
} else {
|
||||
printf("\n ");
|
||||
cols = strlen(pkgver) + 4;
|
||||
}
|
||||
printf("%s ", pkgver);
|
||||
print_package_line(pkgver);
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
printf("\n\n");
|
||||
|
||||
if (only_show)
|
||||
goto out;
|
||||
|
||||
if (!force && !xbps_noyes("Do you want to continue?")) {
|
||||
if (!yes && !xbps_noyes("Do you want to continue?")) {
|
||||
printf("Cancelled!\n");
|
||||
goto out;
|
||||
}
|
||||
@@ -135,14 +120,20 @@ out:
|
||||
}
|
||||
|
||||
int
|
||||
xbps_remove_installed_pkgs(int argc, char **argv, bool force, bool purge)
|
||||
xbps_remove_installed_pkgs(int argc, char **argv, bool yes, bool purge,
|
||||
bool force_rm_with_deps)
|
||||
{
|
||||
prop_array_t sorted_pkgs;
|
||||
prop_array_t reqby;
|
||||
prop_dictionary_t dict;
|
||||
size_t cols = 0;
|
||||
const char *version;
|
||||
size_t x;
|
||||
const char *version, *pkgver, *pkgname;
|
||||
int i, rv = 0;
|
||||
bool found = false, first = false, reqby_force = false;
|
||||
bool found = false, reqby_force = false;
|
||||
|
||||
sorted_pkgs = prop_array_create();
|
||||
if (sorted_pkgs == NULL)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* First check if package is required by other packages.
|
||||
@@ -153,58 +144,58 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool force, bool purge)
|
||||
printf("Package %s is not installed.\n", argv[i]);
|
||||
continue;
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
|
||||
prop_array_add(sorted_pkgs, dict);
|
||||
prop_dictionary_get_cstring_nocopy(dict, "pkgver", &pkgver);
|
||||
found = true;
|
||||
reqby = prop_dictionary_get(dict, "requiredby");
|
||||
if (reqby != NULL && prop_array_count(reqby) > 0) {
|
||||
printf("WARNING: %s-%s IS REQUIRED BY OTHER "
|
||||
"PACKAGES!\n", argv[i], version);
|
||||
printf("WARNING: %s IS REQUIRED BY %u PACKAGES!\n",
|
||||
pkgver, prop_array_count(reqby));
|
||||
reqby_force = true;
|
||||
}
|
||||
prop_object_release(dict);
|
||||
}
|
||||
if (!found)
|
||||
if (!found) {
|
||||
prop_object_release(sorted_pkgs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Show the list of going-to-be removed packages.
|
||||
*/
|
||||
printf("The following packages will be removed:\n\n");
|
||||
for (i = 1; i < argc; i++) {
|
||||
dict = xbps_find_pkg_dict_installed(argv[i], false);
|
||||
if (dict == NULL)
|
||||
continue;
|
||||
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
|
||||
cols += strlen(argv[i]) + strlen(version) + 4;
|
||||
if (cols <= 80) {
|
||||
if (first == false) {
|
||||
printf(" ");
|
||||
first = true;
|
||||
}
|
||||
} else {
|
||||
printf("\n ");
|
||||
cols = strlen(argv[i]) + strlen(version) + 4;
|
||||
}
|
||||
printf("%s-%s ", argv[i], version);
|
||||
prop_object_release(dict);
|
||||
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);
|
||||
}
|
||||
printf("\n\n");
|
||||
if (!force && !xbps_noyes("Do you want to continue?")) {
|
||||
if (!yes && !xbps_noyes("Do you want to continue?")) {
|
||||
printf("Cancelling!\n");
|
||||
prop_object_release(sorted_pkgs);
|
||||
return 0;
|
||||
}
|
||||
if (reqby_force)
|
||||
printf("Forcing removal!\n");
|
||||
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");
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
dict = xbps_find_pkg_dict_installed(argv[i], false);
|
||||
if (dict == NULL)
|
||||
continue;
|
||||
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);
|
||||
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
|
||||
prop_object_release(dict);
|
||||
if ((rv = pkg_remove_and_purge(argv[i], version, purge)) != 0)
|
||||
if ((rv = pkg_remove_and_purge(pkgname, version, purge)) != 0) {
|
||||
prop_object_release(sorted_pkgs);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
prop_object_release(sorted_pkgs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user