pkgsrc-Changes-HG archive

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

[pkgsrc/pkg_install-renovation]: pkgsrc/pkgtools/pkg_install/files Add anothe...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/257a73624953
branches:  pkg_install-renovation
changeset: 541580:257a73624953
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Tue Aug 05 19:01:27 2008 +0000

description:
Add another constant for temporary +REQUIRED_BY files. Don't use mkstemp
in pkg_delete for that purpose. If more than one produce tries to change
this file, breakage will happen anyway and this means the system is
somewhat self-healing.

diffstat:

 pkgtools/pkg_install/files/delete/perform.c |  62 ++++++++++++----------------
 pkgtools/pkg_install/files/lib/lib.h        |   3 +-
 2 files changed, 29 insertions(+), 36 deletions(-)

diffs (114 lines):

diff -r 204ab0a5a496 -r 257a73624953 pkgtools/pkg_install/files/delete/perform.c
--- a/pkgtools/pkg_install/files/delete/perform.c       Tue Aug 05 18:41:44 2008 +0000
+++ b/pkgtools/pkg_install/files/delete/perform.c       Tue Aug 05 19:01:27 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: perform.c,v 1.23.2.3 2008/08/05 18:41:44 joerg Exp $   */
+/*     $NetBSD: perform.c,v 1.23.2.4 2008/08/05 19:01:27 joerg Exp $   */
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -11,7 +11,7 @@
 #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.23.2.3 2008/08/05 18:41:44 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.23.2.4 2008/08/05 19:01:27 joerg Exp $");
 #endif
 #endif
 
@@ -119,32 +119,25 @@
 static int
 undepend(const char *deppkgname, void *vp)
 {
-       char   *pkg2delname = vp;
-       char    fname[MaxPathSize], ftmp[MaxPathSize];
-       char    fbuf[MaxPathSize];
-       FILE   *fp, *fpwr;
-       int     s;
+       char *fname, *fname_tmp;
+       char fbuf[MaxPathSize];
+       const char *pkg2delname = vp;
+       FILE *fp, *fpwr;
 
-       (void) snprintf(fname, sizeof(fname), "%s/%s/%s",
-           _pkgdb_getPKGDB_DIR(), deppkgname, REQUIRED_BY_FNAME);
-       fp = fopen(fname, "r");
-       if (fp == NULL) {
+       fname = pkgdb_pkg_file(deppkgname, REQUIRED_BY_FNAME);
+       fname_tmp = pkgdb_pkg_file(deppkgname, REQUIRED_BY_FNAME_TMP);
+
+       if ((fp = fopen(fname, "r")) == NULL) {
                warnx("couldn't open dependency file `%s'", fname);
+               free(fname);
+               free(fname_tmp);
                return 0;
        }
-       (void) snprintf(ftmp, sizeof(ftmp), "%s.XXXXXX", fname);
-       s = mkstemp(ftmp);
-       if (s == -1) {
+       if ((fpwr = fopen(fname_tmp, "w")) == NULL) {
                fclose(fp);
-               warnx("couldn't open temp file `%s'", ftmp);
-               return 0;
-       }
-       fpwr = fdopen(s, "w");
-       if (fpwr == NULL) {
-               close(s);
-               fclose(fp);
-               warnx("couldn't fdopen temp file `%s'", ftmp);
-               remove(ftmp);
+               warnx("couldn't open temporary file `%s'", fname_tmp);
+               free(fname);
+               free(fname_tmp);
                return 0;
        }
        while (fgets(fbuf, sizeof(fbuf), fp) != NULL) {
@@ -154,20 +147,19 @@
                        fputs(fbuf, fpwr), putc('\n', fpwr);
        }
        (void) fclose(fp);
-       if (fchmod(s, 0644) == FAIL) {
-               warnx("error changing permission of temp file `%s'", ftmp);
-               fclose(fpwr);
-               remove(ftmp);
+       if (fclose(fpwr) == EOF) {
+               warnx("error closing temporary file `%s'", fname_tmp);
+               remove(fname_tmp);
+               free(fname);
+               free(fname_tmp);
                return 0;
        }
-       if (fclose(fpwr) == EOF) {
-               warnx("error closing temp file `%s'", ftmp);
-               remove(ftmp);
-               return 0;
-       }
-       if (rename(ftmp, fname) == -1)
-               warn("error renaming `%s' to `%s'", ftmp, fname);
-       remove(ftmp);           /* just in case */
+       if (rename(fname_tmp, fname) == -1)
+               warn("error renaming `%s' to `%s'", fname_tmp, fname);
+       remove(fname_tmp);      /* just in case */
+
+       free(fname);
+       free(fname_tmp);
 
        return 0;
 }
diff -r 204ab0a5a496 -r 257a73624953 pkgtools/pkg_install/files/lib/lib.h
--- a/pkgtools/pkg_install/files/lib/lib.h      Tue Aug 05 18:41:44 2008 +0000
+++ b/pkgtools/pkg_install/files/lib/lib.h      Tue Aug 05 19:01:27 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.42.2.10 2008/08/02 20:33:50 joerg Exp $ */
+/* $NetBSD: lib.h,v 1.42.2.11 2008/08/05 19:01:27 joerg Exp $ */
 
 /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
 
@@ -112,6 +112,7 @@
 #define INSTALL_FNAME          "+INSTALL"
 #define DEINSTALL_FNAME                "+DEINSTALL"
 #define REQUIRED_BY_FNAME      "+REQUIRED_BY"
+#define REQUIRED_BY_FNAME_TMP  "+REQUIRED_BY.tmp"
 #define DISPLAY_FNAME          "+DISPLAY"
 #define MTREE_FNAME            "+MTREE_DIRS"
 #define BUILD_VERSION_FNAME    "+BUILD_VERSION"



Home | Main Index | Thread Index | Old Index