Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/pkgviews]: src/usr.sbin/pkg_install Teach pkg_delete(1) to delete a view...



details:   https://anonhg.NetBSD.org/src/rev/4ef2342b18b9
branches:  pkgviews
changeset: 534233:4ef2342b18b9
user:      jlam <jlam%NetBSD.org@localhost>
date:      Wed Jul 23 23:03:00 2003 +0000

description:
Teach pkg_delete(1) to delete a view's PKG_DBDIR from the +VIEWS file of
the depoted package.  This lets us use pkg_delete(1) to remove viewed
packages but still keep the information in the +VIEWS consistent with
reality.  At this point, the following two operations yield the same
results for a package "pkgname" installed into view "viewname":

        pkg_view -v viewname delete pkgname
        PKG_DBDIR=/usr/pkg/viewname/.pkgdb pkg_delete pkgname

and for the standard "null" view:

        pkg_view delete pkgname
        pkg_delete pkgname

diffstat:

 usr.sbin/pkg_install/delete/perform.c |  95 ++++++++++++++++++++++++++++++++++-
 usr.sbin/pkg_install/lib/lib.h        |   3 +-
 2 files changed, 95 insertions(+), 3 deletions(-)

diffs (139 lines):

diff -r 05ae2df667e7 -r 4ef2342b18b9 usr.sbin/pkg_install/delete/perform.c
--- a/usr.sbin/pkg_install/delete/perform.c     Wed Jul 23 22:58:24 2003 +0000
+++ b/usr.sbin/pkg_install/delete/perform.c     Wed Jul 23 23:03:00 2003 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: perform.c,v 1.36.2.3 2003/07/15 20:59:39 jlam Exp $    */
+/*     $NetBSD: perform.c,v 1.36.2.4 2003/07/23 23:03:00 jlam Exp $    */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp";
 #else
-__RCSID("$NetBSD: perform.c,v 1.36.2.3 2003/07/15 20:59:39 jlam Exp $");
+__RCSID("$NetBSD: perform.c,v 1.36.2.4 2003/07/23 23:03:00 jlam Exp $");
 #endif
 #endif
 
@@ -166,6 +166,94 @@
 }
 
 /*
+ * Remove the current view's PKG_DBDIR from the +VIEWS file of the
+ * depoted package named by pkgname.
+ */
+static int
+unview(const char *pkgname)
+{
+       char  fname[FILENAME_MAX], ftmp[FILENAME_MAX];
+       char  fbuf[FILENAME_MAX];
+       char  dbdir[FILENAME_MAX];
+       FILE *fp, *fpwr;
+       char *tmp;
+       int  s;
+       int  cc;
+
+       (void) snprintf(dbdir, sizeof(dbdir), "%s",
+           (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR);
+
+       /* Get the depot directory. */
+       (void) snprintf(fname, sizeof(fname), "%s/%s/%s",
+           dbdir, pkgname, DEPOT_FNAME);
+       if ((fp = fopen(fname, "r")) == NULL) {
+               warnx("unable to open `%s' file", fname);
+               return -1;
+       }
+       if (fgets(fbuf, sizeof(fbuf), fp) == NULL) {
+               (void) fclose(fp);
+               warnx("empty depot file `%s'", fname);
+               return -1;
+       }
+       if (fbuf[cc = strlen(fbuf) - 1] == '\n') {
+               fbuf[cc] = 0;
+       }
+       fclose(fp);
+
+       /*
+        * Copy the contents of the +VIEWS file into a temp file, but
+        * skip copying the name of the current view's PKG_DBDIR.
+        */
+       (void) snprintf(fname, sizeof(fname), "%s/%s", fbuf, VIEWS_FNAME);
+       if ((fp = fopen(fname, "r")) == NULL) {
+               warnx("unable to open `%s' file", fname);
+               return -1;
+       }
+       (void) snprintf(ftmp, sizeof(ftmp), "%s.XXXXXX", fname);
+       if ((s = mkstemp(ftmp)) == -1) {
+               (void) fclose(fp);
+               warnx("unable to open `%s' temp file", ftmp);
+               return -1;
+       }
+       if ((fpwr = fdopen(s, "w")) == NULL) {
+               (void) close(s);
+               (void) remove(ftmp);
+               (void) fclose(fp);
+               warnx("unable to fdopen `%s' temp file", ftmp);
+               return -1;
+       }
+       while (fgets(fbuf, sizeof(fbuf), fp) != NULL) {
+               if (fbuf[cc = strlen(fbuf) - 1] == '\n') {
+                       fbuf[cc] = 0;
+               }
+               if (strcmp(fbuf, dbdir) != 0) {
+                       (void) fputs(fbuf, fpwr);
+                       (void) putc('\n', fpwr);
+               }
+       }
+       (void) fclose(fp);
+       if (fchmod(s, 0644) == FAIL) {
+               (void) fclose(fpwr);
+               (void) remove(ftmp);
+               warnx("unable to change permissions of `%s' temp file", ftmp);
+               return -1;
+       }
+       if (fclose(fpwr) == EOF) {
+               (void) remove(ftmp);
+               warnx("unable to close `%s' temp file", ftmp);
+               return -1;
+       }
+
+       /* Rename the temp file to the +VIEWS file */
+       if (rename(ftmp, fname) == -1) {
+               (void) remove(ftmp);
+               warnx("unable to rename `%s' to `%s'", ftmp, fname);
+               return -1;
+       }
+       return 0;
+}
+
+/*
  * Delete from directory 'home' all packages on lpkg_list. 
  * If tryall is set, ignore errors from pkg_delete(1).
  */
@@ -646,6 +734,9 @@
                "couldn't entirely delete package `%s'\n"
                "(perhaps the packing list is incorrectly specified?)", pkg);
        }
+       if (!isemptyfile(DEPOT_FNAME)) {
+               (void) unview(pkg);
+       }
        /* Remove this package from the +REQUIRED_BY list of the packages this depends on */
        for (p = Plist.head; p; p = p->next) {
                if (p->type != PLIST_PKGDEP)
diff -r 05ae2df667e7 -r 4ef2342b18b9 usr.sbin/pkg_install/lib/lib.h
--- a/usr.sbin/pkg_install/lib/lib.h    Wed Jul 23 22:58:24 2003 +0000
+++ b/usr.sbin/pkg_install/lib/lib.h    Wed Jul 23 23:03:00 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.43.2.2 2003/07/13 09:45:27 jlam Exp $ */
+/* $NetBSD: lib.h,v 1.43.2.3 2003/07/23 23:03:01 jlam Exp $ */
 
 /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
 
@@ -113,6 +113,7 @@
 #define SIZE_ALL_FNAME         "+SIZE_ALL"
 #define PRESERVE_FNAME         "+PRESERVE"
 #define VIEWS_FNAME            "+VIEWS"
+#define DEPOT_FNAME            "+DEPOT"
 
 #define CMD_CHAR               '@'     /* prefix for extended PLIST cmd */
 



Home | Main Index | Thread Index | Old Index