pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_install/files Add "rebuild-tree" command ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/562a17d9c046
branches:  trunk
changeset: 532062:562a17d9c046
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Fri Aug 10 21:18:31 2007 +0000

description:
Add "rebuild-tree" command to pkg_admin. It recomputes the dependencies
and builds the +REQUIRED_BY files from that.

Bump to 20070810.

diffstat:

 pkgtools/pkg_install/files/admin/main.c         |  94 ++++++++++++++++++++++++-
 pkgtools/pkg_install/files/admin/pkg_admin.1    |  10 ++-
 pkgtools/pkg_install/files/admin/pkg_admin.cat1 |  10 ++-
 pkgtools/pkg_install/files/lib/version.h        |   4 +-
 4 files changed, 111 insertions(+), 7 deletions(-)

diffs (194 lines):

diff -r b10f5471042f -r 562a17d9c046 pkgtools/pkg_install/files/admin/main.c
--- a/pkgtools/pkg_install/files/admin/main.c   Fri Aug 10 21:11:08 2007 +0000
+++ b/pkgtools/pkg_install/files/admin/main.c   Fri Aug 10 21:18:31 2007 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.24 2007/08/10 00:03:51 joerg Exp $  */
+/*     $NetBSD: main.c,v 1.25 2007/08/10 21:18:31 joerg Exp $  */
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -8,7 +8,7 @@
 #include <sys/cdefs.h>
 #endif
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.24 2007/08/10 00:03:51 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.25 2007/08/10 21:18:31 joerg Exp $");
 #endif
 
 /*
@@ -450,6 +450,90 @@
        return 0;
 }
 
+static int
+remove_required_by(const char *pkgname, void *cookie)
+{
+       char *path;
+
+       if (asprintf(&path, "%s/%s/%s", _pkgdb_getPKGDB_DIR(), pkgname,
+                    REQUIRED_BY_FNAME) == -1)
+               errx(EXIT_FAILURE, "asprintf failed");
+
+       if (unlink(path) == -1 && errno != ENOENT)
+               err(EXIT_FAILURE, "Cannot remove %s", path);
+
+       free(path);
+
+       return 0;
+}
+
+static void
+add_required_by(const char *pattern, const char *required_by)
+{
+       char *best_installed, *path;
+       int fd;
+       size_t len;
+
+       best_installed = find_best_matching_installed_pkg(pattern);
+       if (best_installed == NULL) {
+               warnx("Dependency %s of %s unresolved", pattern, required_by);
+               return;
+       }
+
+       if (asprintf(&path, "%s/%s/%s", _pkgdb_getPKGDB_DIR(), best_installed,
+                    REQUIRED_BY_FNAME) == -1)
+               errx(EXIT_FAILURE, "asprintf failed");
+       free(best_installed);
+
+       if ((fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0644)) == -1)
+               errx(EXIT_FAILURE, "Cannot write to %s", path);
+       free(path);
+       
+       len = strlen(required_by);
+       if (write(fd, required_by, len) != len ||
+           write(fd, "\n", 1) != 1 ||
+           close(fd) == -1)
+               errx(EXIT_FAILURE, "Cannot write to %s", path);
+}
+
+
+static int
+add_depends_of(const char *pkgname, void *cookie)
+{
+       FILE *fp;
+       plist_t *p;
+       package_t plist;
+       char *path;
+
+       if (asprintf(&path, "%s/%s/%s", _pkgdb_getPKGDB_DIR(), pkgname,
+                    CONTENTS_FNAME) == -1)
+               errx(EXIT_FAILURE, "asprintf failed");
+       if ((fp = fopen(path, "r")) == NULL)
+               errx(EXIT_FAILURE, "Cannot read %s of package %s",
+                   CONTENTS_FNAME, pkgname);
+       free(path);
+       read_plist(&plist, fp);
+       fclose(fp);
+
+       for (p = plist.head; p; p = p->next) {
+               if (p->type == PLIST_PKGDEP)
+                       add_required_by(p->name, pkgname);
+       }
+
+       free_plist(&plist);     
+
+       return 0;
+}
+
+static void
+rebuild_tree(void)
+{
+       if (iterate_pkg_db(remove_required_by, NULL) == -1)
+               errx(EXIT_FAILURE, "cannot iterate pkgdb");
+       if (iterate_pkg_db(add_depends_of, NULL) == -1)
+               errx(EXIT_FAILURE, "cannot iterate pkgdb");
+}
+
 int 
 main(int argc, char *argv[])
 {
@@ -537,6 +621,12 @@
                rebuild();
                printf("Done.\n");
 
+         
+       } else if (strcasecmp(argv[0], "rebuild-tree") == 0) {
+
+               rebuild_tree();
+               printf("Done.\n");
+
        } else if (strcasecmp(argv[0], "check") == 0) {
 
                argv++;         /* "check" */
diff -r b10f5471042f -r 562a17d9c046 pkgtools/pkg_install/files/admin/pkg_admin.1
--- a/pkgtools/pkg_install/files/admin/pkg_admin.1      Fri Aug 10 21:11:08 2007 +0000
+++ b/pkgtools/pkg_install/files/admin/pkg_admin.1      Fri Aug 10 21:18:31 2007 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: pkg_admin.1,v 1.12 2007/07/16 09:57:57 joerg Exp $
+.\"    $NetBSD: pkg_admin.1,v 1.13 2007/08/10 21:18:31 joerg Exp $
 .\"
 .\" Copyright (c) 1999-2002 Hubert Feyrer.  All rights reserved.
 .\"
@@ -28,7 +28,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd March 2, 2007
+.Dd March 10, 2007
 .Dt PKG_ADMIN 1
 .Os
 .Sh NAME
@@ -195,6 +195,12 @@
 .Xr pkg_create 1 .
 .Pp
 Needs to be run as root.
+.It Cm rebuild-tree
+Rebuild the +REQUIRED_BY files from scratch by reresolving all dependencies.
+.Pp
+This option is intended to be used for fixing the state after forced
+removal or additions of packages like done by
+.Cm make replace .
 .It Cm set Ar variable=value pkg ...
 Set variable with information about the installed package.
 Use
diff -r b10f5471042f -r 562a17d9c046 pkgtools/pkg_install/files/admin/pkg_admin.cat1
--- a/pkgtools/pkg_install/files/admin/pkg_admin.cat1   Fri Aug 10 21:11:08 2007 +0000
+++ b/pkgtools/pkg_install/files/admin/pkg_admin.cat1   Fri Aug 10 21:18:31 2007 +0000
@@ -121,6 +121,14 @@
 
              Needs to be run as root.
 
+     rreebbuuiilldd--ttrreeee
+             Rebuild the +REQUIRED_BY files from scratch by reresolving all
+             dependencies.
+
+             This option is intended to be used for fixing the state after
+             forced removal or additions of packages like done by mmaakkee
+             rreeppllaaccee.
+
      sseett _v_a_r_i_a_b_l_e_=_v_a_l_u_e _p_k_g _._._.
              Set variable with information about the installed package.  Use
              uunnsseett to remove a variable.
@@ -151,4 +159,4 @@
 AAUUTTHHOORRSS
      The ppkkgg__aaddmmiinn command was written by Hubert Feyrer.
 
-NetBSD 4.0                       March 2, 2007                      NetBSD 4.0
+NetBSD 4.0                      March 10, 2007                      NetBSD 4.0
diff -r b10f5471042f -r 562a17d9c046 pkgtools/pkg_install/files/lib/version.h
--- a/pkgtools/pkg_install/files/lib/version.h  Fri Aug 10 21:11:08 2007 +0000
+++ b/pkgtools/pkg_install/files/lib/version.h  Fri Aug 10 21:18:31 2007 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.74 2007/08/09 18:03:38 joerg Exp $       */
+/*     $NetBSD: version.h,v 1.75 2007/08/10 21:18:32 joerg Exp $       */
 
 /*
  * Copyright (c) 2001 Thomas Klausner.  All rights reserved.
@@ -33,6 +33,6 @@
 #ifndef _INST_LIB_VERSION_H_
 #define _INST_LIB_VERSION_H_
 
-#define PKGTOOLS_VERSION "20070809"
+#define PKGTOOLS_VERSION "20070810"
 
 #endif /* _INST_LIB_VERSION_H_ */



Home | Main Index | Thread Index | Old Index