Skip to content

Commit

Permalink
Fixes for uninstall programs to handle uninstall messages on the console
Browse files Browse the repository at this point in the history
  • Loading branch information
megastep committed Jun 6, 2003
1 parent be4d480 commit b50fd56
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
61 changes: 53 additions & 8 deletions uninstall.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Parses the product INI file in ~/.loki/installed/ and uninstalls the software.
*/

/* $Id: uninstall.c,v 1.35 2003-05-02 22:54:49 zeph Exp $ */
/* $Id: uninstall.c,v 1.36 2003-06-06 20:48:06 megastep Exp $ */

#include <stdlib.h>
#include <stdio.h>
Expand Down Expand Up @@ -125,6 +125,7 @@ static void emergency_exit(int sig)
/* Try to save the XML file */
loki_closeproduct(prod);
}
exit(2);
}

int uninstall_component(product_component_t *comp, product_info_t *info)
Expand Down Expand Up @@ -204,7 +205,27 @@ int uninstall_component(product_component_t *comp, product_info_t *info)
return 1;
}

int perform_uninstall(product_t *prod, product_info_t *info)
static int check_for_message(product_component_t *comp)
{
const char *message = loki_getmessage_component(comp);

if ( message ) {
puts(message);
if ( isatty(0) ) { /* If we have a TTY, try to get user input */
int c;
printf(_("Uninstall ? [Y/n] "));
fflush(stdin);
c = getchar();
if ( c == 'n' || c == 'N' ) {
printf(_("Aborted.\n"));
return 0;
}
}
}
return 1;
}

int perform_uninstall(product_t *prod, product_info_t *info, int console)
{
product_component_t *comp, *next;
int ret = 1;
Expand All @@ -213,13 +234,21 @@ int perform_uninstall(product_t *prod, product_info_t *info)
while ( comp && ret ) {
next = loki_getnext_component(comp);
if ( ! loki_isdefault_component(comp) ) {
if ( console && ! check_for_message(comp) ) {
ret = 0;
break;
}
ret = uninstall_component(comp, info);
}
comp = next;
}
comp = loki_getdefault_component(prod);
if ( comp && ret ) {
ret = uninstall_component(comp, info);
if ( !console || check_for_message(comp) ) {
ret = uninstall_component(comp, info);
} else {
ret = 0;
}
}

if ( ret ) {
Expand Down Expand Up @@ -485,8 +514,14 @@ printf("\n\n");
prod = loki_openproduct(product);
printf("\t%s: ", product);
if ( prod ) {
product_component_t *comp;

info = loki_getinfo_product(prod);
printf(_("installed in %s\n"), info->root);
printf(_("installed in %s\n\tComponents:\n"), info->root);
/* List components */
for ( comp = loki_getfirst_component(prod); comp; comp = loki_getnext_component(comp)) {
printf("\t\t%s\n", loki_getname_component(comp));
}
loki_closeproduct(prod);
} else {
printf(_(" Error while accessing product info\n"));
Expand All @@ -498,6 +533,16 @@ printf("\n\n");
#else
printf("%d.%d.%d\n", SETUP_VERSION_MAJOR, SETUP_VERSION_MINOR, SETUP_VERSION_RELEASE);
#endif
} else if ( !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ) {
fprintf(stderr,
_("Usage: %s [args]\n"
"args can be any of the following:\n\n"
" -l : List all installed products and components.\n"
" -v | --version : Get version information.\n"
" -h | --help : Print this help message.\n"
" product [component] : Uninstalls the specified product, or its subcomponent.\n"
), argv[0]);
return 0;
} else {
prod = loki_openproduct(argv[1]);
if ( ! prod ) {
Expand All @@ -522,11 +567,11 @@ printf("\n\n");
} else { /* Uninstall a single component */
comp = loki_find_component(prod, argv[2]);
if ( comp ) {
const char *message = loki_getmessage_component(comp);

if ( ! check_permissions(info, 1) )
return 1;
if ( message ) {
puts(message);
if ( ! check_for_message(comp) ) {
return 1;
}
if ( ! uninstall_component(comp, info) ) {
fprintf(stderr, _("Failed to properly uninstall component %s\n"), argv[2]);
Expand All @@ -543,7 +588,7 @@ printf("\n\n");
/* Uninstall the damn thing */
if ( ! check_permissions(info, 1) )
return 1;
if ( ! perform_uninstall(prod, info) ) {
if ( ! perform_uninstall(prod, info, 1) ) {
fprintf(stderr, _("An error occured during the uninstallation process.\n"));
ret = 1;
loki_closeproduct(prod);
Expand Down
4 changes: 2 additions & 2 deletions uninstall.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Parses the product INI file in ~/.loki/installed/ and uninstalls the software.
*/

/* $Id: uninstall.h,v 1.9 2003-03-21 07:33:16 megastep Exp $ */
/* $Id: uninstall.h,v 1.10 2003-06-06 20:48:06 megastep Exp $ */

extern product_t *prod;

Expand All @@ -13,4 +13,4 @@ extern int check_permissions(product_info_t *info, int verbose);
extern int uninstall_component(product_component_t *comp, product_info_t *info);

/* Uninstall an entire product */
extern int perform_uninstall(product_t *prod, product_info_t *info);
extern int perform_uninstall(product_t *prod, product_info_t *info, int console);
2 changes: 1 addition & 1 deletion uninstall_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void perform_uninstall_slot(GtkWidget* w, gpointer data)
}

/* Remove the component */
if ( ! perform_uninstall(component->product, component->info) ) {
if ( ! perform_uninstall(component->product, component->info, 0) ) {
uninstall_cancelled = 2;
snprintf(text, sizeof(text), _("Uninstallation of product %s has failed!\n"
"Aborting the rest of the uninstallation.\n"),
Expand Down

0 comments on commit b50fd56

Please sign in to comment.