summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorjoerg <joerg>2007-08-10 21:18:31 +0000
committerjoerg <joerg>2007-08-10 21:18:31 +0000
commitbc53c6ac21201b8ab4fb1bb6211312f2bc32831e (patch)
tree445534c275444d712a569aecf682005c6f54e0b9 /pkgtools
parent58908448ee831e2bceadab32b5051c570a6f33b1 (diff)
downloadpkgsrc-bc53c6ac21201b8ab4fb1bb6211312f2bc32831e.tar.gz
Add "rebuild-tree" command to pkg_admin. It recomputes the dependencies
and builds the +REQUIRED_BY files from that. Bump to 20070810.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkg_install/files/admin/main.c94
-rw-r--r--pkgtools/pkg_install/files/admin/pkg_admin.110
-rw-r--r--pkgtools/pkg_install/files/admin/pkg_admin.cat110
-rw-r--r--pkgtools/pkg_install/files/lib/version.h4
4 files changed, 111 insertions, 7 deletions
diff --git a/pkgtools/pkg_install/files/admin/main.c b/pkgtools/pkg_install/files/admin/main.c
index 79b5b10e125..e5be3717af0 100644
--- a/pkgtools/pkg_install/files/admin/main.c
+++ b/pkgtools/pkg_install/files/admin/main.c
@@ -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 @@ lsbasepattern_fn(const char *pattern, const char *pkg, void *vp)
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 @@ main(int argc, char *argv[])
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 --git a/pkgtools/pkg_install/files/admin/pkg_admin.1 b/pkgtools/pkg_install/files/admin/pkg_admin.1
index 91cd15017a2..5fe5693c370 100644
--- a/pkgtools/pkg_install/files/admin/pkg_admin.1
+++ b/pkgtools/pkg_install/files/admin/pkg_admin.1
@@ -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 @@ and
.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 --git a/pkgtools/pkg_install/files/admin/pkg_admin.cat1 b/pkgtools/pkg_install/files/admin/pkg_admin.cat1
index 1d468f9cdec..53af1756359 100644
--- a/pkgtools/pkg_install/files/admin/pkg_admin.cat1
+++ b/pkgtools/pkg_install/files/admin/pkg_admin.cat1
@@ -121,6 +121,14 @@ OOPPTTIIOONNSS
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 @@ HHIISSTTOORRYY
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 --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h
index 725a6debcc7..4ad954fb69f 100644
--- a/pkgtools/pkg_install/files/lib/version.h
+++ b/pkgtools/pkg_install/files/lib/version.h
@@ -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_ */