diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2000-04-28 21:08:17 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2000-04-28 21:08:17 +0000 |
commit | c9f4804d458f54d54c8d99a241feee035b096b25 (patch) | |
tree | f528cc823c416507eaceb77f70a0709fd968af1a /usr.sbin | |
parent | 90750be49bb97ad6a5bb575605f9f3abce0e4d02 (diff) |
If symlinks to the package exist, remove them along with the package.
(current fix for flavors not being found as proper dependencies).
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_install/delete/perform.c | 58 |
1 files changed, 49 insertions, 9 deletions
diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index dc3a001a8ab..9320b6af4db 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -1,7 +1,7 @@ -/* $OpenBSD: perform.c,v 1.7 2000/03/24 00:21:28 espie Exp $ */ +/* $OpenBSD: perform.c,v 1.8 2000/04/28 21:08:16 espie Exp $ */ #ifndef lint -static const char *rcsid = "$OpenBSD: perform.c,v 1.7 2000/03/24 00:21:28 espie Exp $"; +static const char *rcsid = "$OpenBSD: perform.c,v 1.8 2000/04/28 21:08:16 espie Exp $"; #endif /* @@ -71,6 +71,46 @@ trim_end(char *name) return 0; } +/* remove all links to the package as well */ +static void +delete_pkg_links(const char *dir, const char *pkg) +{ + int base; + int len; + DIR *d; + struct dirent *dp; + struct stat sb; + char name[FILENAME_MAX+1]; + + base = open(".", O_RDONLY); + if (base == -1) + return; + if (chdir(dir) == -1) { + close(base); + return; + } + d = opendir("."); + if (d == NULL) { + fchdir(base); + close(base); + return; + } + while ((dp = readdir(d)) != NULL) { + if (lstat(dp->d_name, &sb) == -1 || !S_ISLNK(sb.st_mode)) + continue; + len = readlink(dp->d_name, name, FILENAME_MAX); + if (len == -1) + continue; + name[len] = 0; + if (strcmp(name, pkg)) + continue; + unlink(dp->d_name); + } + closedir(d); + fchdir(base); + close(base); +} + /* This is seriously ugly code following. Written very fast! */ static int pkg_do(char *pkg) @@ -78,17 +118,17 @@ pkg_do(char *pkg) FILE *cfile; char home[FILENAME_MAX]; plist_t *p; - char *tmp; + char *dbdir; /* Reset some state */ if (Plist.head) free_plist(&Plist); - tmp = getenv(PKG_DBDIR); - if (!tmp) - tmp = DEF_LOG_DIR; + dbdir = getenv(PKG_DBDIR); + if (!dbdir) + dbdir = DEF_LOG_DIR; try_again: - (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", tmp, pkg); + (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", dbdir, pkg); if (!fexists(LogDir)) { if (trim_end(pkg)) goto try_again; @@ -189,6 +229,7 @@ try_again: if (!Force) return 1; } + delete_pkg_links(dbdir, pkg); } for (p = Plist.head; p ; p = p->next) { if (p->type != PLIST_PKGDEP) @@ -196,8 +237,7 @@ try_again: if (Verbose) printf("Attempting to remove dependency on package `%s'\n", p->name); if (!Fake) - findmatchingname((tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, - p->name, undepend, pkg); + findmatchingname(dbdir, p->name, undepend, pkg); } return 0; } |