diff options
Diffstat (limited to 'usr.sbin/pkg_install/delete/perform.c')
-rw-r--r-- | usr.sbin/pkg_install/delete/perform.c | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index c1bc803..76bb734 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -125,6 +125,7 @@ pkg_do(char *pkg) char *deporigin, **depnames, home[FILENAME_MAX]; PackingList p; int i, len; + int isinstalled; /* support for separate pre/post install scripts */ int new_m = 0; const char *pre_script = DEINSTALL_FNAME; @@ -141,9 +142,26 @@ pkg_do(char *pkg) if (Plist.head) free_plist(&Plist); - if (!isinstalledpkg(pkg)) { + sprintf(LogDir, "%s/%s", LOG_DIR, pkg); + + isinstalled = isinstalledpkg(pkg); + if (isinstalled == 0) { warnx("no such package '%s' installed", pkg); return 1; + } else if (isinstalled < 0) { + warnx("the package info for package '%s' is corrupt%s", + pkg, Force ? " (but I'll delete it anyway)" : " (use -f to force removal)"); + if (!Force) + return 1; + if (!Fake) { + if (vsystem("%s -rf %s", REMOVE_CMD, LogDir)) { + warnx("couldn't remove log entry in %s, deinstall failed", LogDir); + } else { + warnx("couldn't completely deinstall package '%s',\n" + "only the log entry in %s was removed", pkg, LogDir); + } + } + return 0; } if (!getcwd(home, FILENAME_MAX)) { @@ -151,8 +169,6 @@ pkg_do(char *pkg) errx(2, "%s: unable to get current working directory!", __func__); } - sprintf(LogDir, "%s/%s", LOG_DIR, pkg); - if (chdir(LogDir) == FAIL) { warnx("unable to change directory to %s! deinstall failed", LogDir); return 1; @@ -247,6 +263,30 @@ pkg_do(char *pkg) } } + for (p = Plist.head; p ; p = p->next) { + if (p->type != PLIST_PKGDEP) + continue; + deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : + NULL; + if (Verbose) { + printf("Trying to remove dependency on package '%s'", p->name); + if (deporigin != NULL) + printf(" with '%s' origin", deporigin); + printf(".\n"); + } + if (!Fake) { + depnames = (deporigin != NULL) ? matchbyorigin(deporigin, NULL) : + NULL; + if (depnames == NULL) { + depnames = alloca(sizeof(*depnames) * 2); + depnames[0] = p->name; + depnames[1] = NULL; + } + for (i = 0; depnames[i] != NULL; i++) + undepend(depnames[i], pkg); + } + } + if (chdir(home) == FAIL) { cleanup(0); errx(2, "%s: unable to return to working directory %s!", __func__, @@ -293,30 +333,6 @@ pkg_do(char *pkg) return 1; } } - - for (p = Plist.head; p ; p = p->next) { - if (p->type != PLIST_PKGDEP) - continue; - deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : - NULL; - if (Verbose) { - printf("Trying to remove dependency on package '%s'", p->name); - if (deporigin != NULL) - printf(" with '%s' origin", deporigin); - printf(".\n"); - } - if (!Fake) { - depnames = (deporigin != NULL) ? matchbyorigin(deporigin, NULL) : - NULL; - if (depnames == NULL) { - depnames = alloca(sizeof(*depnames) * 2); - depnames[0] = p->name; - depnames[1] = NULL; - } - for (i = 0; depnames[i] != NULL; i++) - undepend(depnames[i], pkg); - } - } return 0; } |