Subject: Re: Support for marking packages as installed automatically as dependencies
To: None <tech-pkg@NetBSD.org>
From: Thomas Klausner <wiz@NetBSD.org>
List: tech-pkg
Date: 10/24/2005 12:30:02
--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Mon, Oct 24, 2005 at 09:31:14AM +0200, Joerg Sonnenberger wrote:
> Nice. Can you also add an option to pkg_admin to change the state?
That's already in the patch.
pkg_admin set automatic=[yes|no]
> It
> might also be useful to handle that in the already-installed case for
> pkg_install.
We've added a few lines that change the state from automatic=yes
to automatic=no if you pkg_add an already installed package manually.
Thomas
--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pkg_install-20051023a.diff"
? pkg_install-20051020.diff
Index: add/add.h
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/add/add.h,v
retrieving revision 1.7
diff -u -r1.7 add.h
--- add/add.h 10 Dec 2004 21:49:31 -0000 1.7
+++ add/add.h 23 Oct 2005 20:01:46 -0000
@@ -36,6 +36,7 @@
extern Boolean NoInstall;
extern Boolean NoRecord;
extern Boolean Force;
+extern Boolean Automatic;
extern int Replace;
extern char *Mode;
extern char *Owner;
Index: add/main.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/add/main.c,v
retrieving revision 1.34
diff -u -r1.34 main.c
--- add/main.c 29 Dec 2004 11:34:59 -0000 1.34
+++ add/main.c 23 Oct 2005 20:01:46 -0000
@@ -37,7 +37,7 @@
#include "add.h"
#include "verify.h"
-static char Options[] = "IK:LMRSVW:fhnp:s:t:uvw:";
+static char Options[] = "AIK:LMRSVW:fhnp:s:t:uvw:";
char *Prefix = NULL;
char *View = NULL;
@@ -45,6 +45,7 @@
Boolean NoView = FALSE;
Boolean NoInstall = FALSE;
Boolean NoRecord = FALSE;
+Boolean Automatic = FALSE;
char *Mode = NULL;
char *Owner = NULL;
@@ -59,7 +60,7 @@
usage(void)
{
(void) fprintf(stderr, "%s\n%s\n%s\n",
- "usage: pkg_add [-fhILMnRSuVv] [-p prefix] [-s verification-type]",
+ "usage: pkg_add [-AfhILMnRSuVv] [-p prefix] [-s verification-type]",
" [-t template] [-W viewbase] [-w view]",
" pkg-name [pkg-name ...]");
exit(1);
@@ -76,6 +77,10 @@
setprogname(argv[0]);
while ((ch = getopt(argc, argv, Options)) != -1) {
switch (ch) {
+ case 'A':
+ Automatic = TRUE;
+ break;
+
case 'f':
Force = TRUE;
break;
Index: add/perform.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/add/perform.c,v
retrieving revision 1.111
diff -u -r1.111 perform.c
--- add/perform.c 18 Jul 2005 09:06:48 -0000 1.111
+++ add/perform.c 23 Oct 2005 20:01:46 -0000
@@ -149,7 +149,8 @@
Viewbase ? "-W" : "", Viewbase ? Viewbase : "",
Force ? "-f" : "",
Prefix ? "-p" : "", Prefix ? Prefix : "",
- Verbose ? "-v" : "", name, NULL)) {
+ Verbose ? "-v" : "",
+ "-A", name, NULL)) {
warnx("autoload of dependency `%s' failed%s",
name, Force ? " (proceeding anyway)" : "!");
if (!Force)
@@ -456,7 +457,15 @@
/* See if this package (exact version) is already registered */
if ((isdir(LogDir) || islinktodir(LogDir)) && !Force) {
- warnx("package `%s' already recorded as installed", PkgName);
+ if (!Automatic && is_automatic_installed(LogDir)) {
+ mark_as_automatic_installed(LogDir, 0);
+ warnx("package `%s' was already installed as "
+ "dependency, now marked as installed manually",
+ PkgName);
+ } else {
+ warnx("package `%s' already recorded as installed",
+ PkgName);
+ }
goto success; /* close enough for government work */
}
@@ -900,6 +909,8 @@
warnx("cannot properly close file %s", contents);
}
}
+ if (Automatic)
+ mark_as_automatic_installed(LogDir, 1);
if (Verbose)
printf("Package %s registered in %s\n", PkgName, LogDir);
}
@@ -1023,4 +1034,3 @@
return err_cnt;
}
-
Index: add/pkg_add.1
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/add/pkg_add.1,v
retrieving revision 1.60
diff -u -r1.60 pkg_add.1
--- add/pkg_add.1 18 Jul 2005 09:06:49 -0000 1.60
+++ add/pkg_add.1 23 Oct 2005 20:01:47 -0000
@@ -17,7 +17,7 @@
.\"
.\" @(#)pkg_add.1
.\"
-.Dd July 13, 2005
+.Dd October 23, 2005
.Dt PKG_ADD 1
.Os
.Sh NAME
@@ -25,25 +25,13 @@
.Nd a utility for installing and upgrading software package distributions
.Sh SYNOPSIS
.Nm
-.Op Fl fILMnRSuVv
-.Bk -words
+.Op Fl AfILMnRSuVv
.Op Fl K Ar pkg_dbdir
-.Ek
-.Bk -words
.Op Fl p Ar prefix
-.Ek
-.Bk -words
.Op Fl s Ar verification-type
-.Ek
-.Bk -words
.Op Fl t Ar template
-.Ek
-.Bk -words
.Op Fl W Ar viewbase
-.Ek
-.Bk -words
.Op Fl w Ar view
-.Ek
.Ar \fR[[ftp|http]://[\fIuser\fR[:\fIpassword]\fR@]\fIhost\fR[:\fIport\fR]][/\fIpath/\fR]pkg-name ...
.Sh DESCRIPTION
The
@@ -114,6 +102,12 @@
environment variable.
Any dependencies required by the installed package will be searched
in the same location that the original package was installed from.
+.It Fl A
+Mark package as installed automatically, as dependency of another
+package.
+.Nm pkg_admin Cm set
+can be used to mark packages this way after installation, or to
+remove the mark.
.It Fl f
Force installation to proceed even if prerequisite packages are not
installed or the requirements script fails.
Index: admin/main.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/admin/main.c,v
retrieving revision 1.48
diff -u -r1.48 main.c
--- admin/main.c 11 Mar 2005 22:52:04 -0000 1.48
+++ admin/main.c 23 Oct 2005 20:01:47 -0000
@@ -57,10 +57,11 @@
static int quiet;
static int checkpattern_fn(const char *, void *);
+static void set_variable(char **);
/* print usage message and exit */
static void
-usage(const char *prog)
+usage(void)
{
(void) fprintf(stderr, "usage: %s [-bqSV] [-d lsdir] [-K pkg_dbdir] [-s sfx] command args ...\n"
"Where 'commands' and 'args' are:\n"
@@ -68,6 +69,7 @@
" check [pkg ...] - check md5 checksum of installed files\n"
" add pkg ... - add pkg files to database\n"
" delete pkg ... - delete file entries for pkg in database\n"
+ " set automatic=[yes|no] pkg ... - set package's automatic value\n"
#ifdef PKGDB_DEBUG
" addkey key value - add key and value\n"
" delkey key - delete reference to key\n"
@@ -76,7 +78,7 @@
" lsbest /path/to/pkgpattern - list pkgs matching the pattern best\n"
" dump - dump database\n"
" pmatch pattern pkg - returns true if pkg matches pattern, otherwise false\n",
- prog);
+ getprogname());
exit(EXIT_FAILURE);
}
@@ -420,7 +422,6 @@
int
main(int argc, char *argv[])
{
- const char *prog;
Boolean use_default_sfx = TRUE;
Boolean show_basename_only = FALSE;
char lsdir[MaxPathSize];
@@ -428,10 +429,10 @@
char *lsdirp = NULL;
int ch;
- setprogname(prog = argv[0]);
+ setprogname(argv[0]);
if (argc < 2)
- usage(prog);
+ usage();
while ((ch = getopt(argc, argv, Options)) != -1)
switch (ch) {
@@ -467,7 +468,7 @@
break;
default:
- usage(prog);
+ usage();
/* NOTREACHED */
}
@@ -475,7 +476,7 @@
argv += optind;
if (argc <= 0) {
- usage(prog);
+ usage();
}
if (use_default_sfx)
@@ -488,7 +489,7 @@
argv++; /* "pmatch" */
if (argv[0] == NULL || argv[1] == NULL) {
- usage(prog);
+ usage();
}
pattern = argv[0];
@@ -666,6 +667,9 @@
delete1pkg(*argv);
argv++;
}
+ } else if (strcasecmp(argv[0], "set") == 0) {
+ argv++; /* "set" */
+ set_variable(argv);
}
#ifdef PKGDB_DEBUG
else if (strcasecmp(argv[0], "delkey") == 0) {
@@ -710,12 +714,73 @@
}
#endif
else {
- usage(prog);
+ usage();
}
return 0;
}
+static int
+mark_as_automatic_installed_wrapper(const char *name, void *value)
+{
+ return mark_as_automatic_installed(name, *(int *)value);
+}
+
+static void
+set_variable(char **argv)
+{
+ char *eq;
+ int mark_auto = -1;
+ int ret = 0;
+
+ eq = NULL;
+ if (argv[0] == NULL || argv[1] == NULL
+ || (eq=strchr(argv[0], '=')) == NULL)
+ usage();
+ if (strncmp(argv[0], "automatic", eq-argv[0]) != 0)
+ errx(EXIT_FAILURE, "unknown variable `%.*s'",
+ eq-argv[0], argv[0]);
+ if (strcasecmp(eq+1, "yes") == 0)
+ mark_auto = 1;
+ else if (strcasecmp(eq+1, "no") == 0)
+ mark_auto = 0;
+ else
+ errx(EXIT_FAILURE, "unknown value `%s'", eq+1);
+
+ chdir(_pkgdb_getPKGDB_DIR());
+ argv++;
+ while (*argv != NULL) {
+ if (ispkgpattern(*argv)) {
+ if (findmatchingname(_pkgdb_getPKGDB_DIR(),
+ *argv, mark_as_automatic_installed_wrapper,
+ &mark_auto) <= 0) {
+ warnx("no matching pkg for `%s'", *argv);
+ ret++;
+ }
+ } else if (isdir(*argv) || islinktodir(*argv))
+ mark_as_automatic_installed(*argv, mark_auto);
+ else {
+ /* try 'pkg-[0-9]*' */
+ char try[MaxPathSize];
+
+ snprintf(try, sizeof(try), "%s-[0-9]*", *argv);
+ if (findmatchingname(_pkgdb_getPKGDB_DIR(),
+ try, mark_as_automatic_installed_wrapper,
+ &mark_auto) <= 0) {
+ warnx("cannot find package %s", *argv);
+ ret++;
+ }
+ }
+
+ argv++;
+ }
+
+ if (ret > 0)
+ exit(EXIT_FAILURE);
+
+ return;
+}
+
void
cleanup(int signo)
{
Index: admin/pkg_admin.1
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/admin/pkg_admin.1,v
retrieving revision 1.35
diff -u -r1.35 pkg_admin.1
--- admin/pkg_admin.1 26 Feb 2005 14:09:58 -0000 1.35
+++ admin/pkg_admin.1 23 Oct 2005 20:01:47 -0000
@@ -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 August 13, 2004
+.Dd October 23, 2005
.Dt PKG_ADMIN 1
.Os
.Sh NAME
@@ -37,14 +37,9 @@
.Sh SYNOPSIS
.Nm
.Op Fl bqSV
-.Nb -words
.Op Fl d Ar lsdir
-.Bk -words
.Op Fl K Ar pkg_dbdir
-.Ek
-.Bk -words
.Op Fl s Ar sfx_pattern
-.Ek
.Ar command Op args ...
.Sh DESCRIPTION
This command performs various administrative tasks around the
@@ -200,7 +195,10 @@
.Xr pkg_create 1 .
.Pp
Needs to be run as root.
-.Pp
+.It Cm set Ar automatic= Ns Bo yes|no Bc Ar pkg ...
+If packages are not installed directly by the user but pulled in as
+dependencies, they are marked as automatically installed.
+This command sets or clears that mark.
.El
.Sh ENVIRONMENT
.Bl -tag -width indent -compact
Index: info/info.h
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/info/info.h,v
retrieving revision 1.20
diff -u -r1.20 info.h
--- info/info.h 16 Feb 2005 08:35:26 -0000 1.20
+++ info/info.h 23 Oct 2005 20:01:47 -0000
@@ -52,6 +52,9 @@
#define SHOW_ALL_SIZE 0x10000
#define SHOW_BLD_DEPENDS 0x20000
#define SHOW_BI_VAR 0x40000
+#define SHOW_ALL_PACKAGES 0x80000
+
+#define AUTOMATIC_STRING "automatic"
extern int Flags;
extern Boolean AllInstalled;
Index: info/main.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/info/main.c,v
retrieving revision 1.45
diff -u -r1.45 main.c
--- info/main.c 10 Feb 2005 22:52:31 -0000 1.45
+++ info/main.c 23 Oct 2005 20:01:47 -0000
@@ -77,7 +77,7 @@
break;
case 'a':
- AllInstalled = TRUE;
+ Flags |= SHOW_ALL_PACKAGES;
break;
case 'B':
@@ -199,8 +199,8 @@
argc -= optind;
argv += optind;
- if (argc == 0 && !Flags && !CheckPkg) {
- /* No argument or flags specified - assume -Ia */
+ if (argc == 0 && !(Flags&~SHOW_ALL_PACKAGES) && !CheckPkg) {
+ /* No argument or relevant flags specified - assume -I */
Flags = SHOW_INDEX;
AllInstalled = TRUE;
}
@@ -214,7 +214,7 @@
path_create(getenv("PKG_PATH"));
/* Set some reasonable defaults */
- if (!Flags)
+ if (!(Flags&~SHOW_ALL_PACKAGES))
Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY
| SHOW_DEPENDS | SHOW_DISPLAY;
Index: info/perform.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/info/perform.c,v
retrieving revision 1.62
diff -u -r1.62 perform.c
--- info/perform.c 20 Feb 2005 14:41:05 -0000 1.62
+++ info/perform.c 23 Oct 2005 20:01:47 -0000
@@ -170,7 +170,13 @@
(void) snprintf(tmp, sizeof(tmp), "%-19s ", pkg);
show_index(pkg, tmp, COMMENT_FNAME);
} else if (Flags & SHOW_BI_VAR) {
- show_var(BUILD_INFO_FNAME, BuildInfoVariable);
+ if (strcmp(BuildInfoVariable, AUTOMATIC_STRING) == 0) {
+ if (is_automatic_installed(".") == TRUE)
+ puts("yes");
+ else
+ puts("no");
+ } else
+ show_var(BUILD_INFO_FNAME, BuildInfoVariable);
} else {
FILE *fp;
package_t plist;
@@ -347,12 +353,10 @@
return 1;
if (File2Pkg) {
-
/* Show all files with the package they belong to */
pkgdb_dump();
-
} else {
- /* Show all packges with description */
+ /* Show all packages with description */
if ((dirp = opendir(dbdir)) != (DIR *) NULL) {
while ((dp = readdir(dirp)) != (struct dirent *) NULL) {
char tmp2[MaxPathSize];
@@ -366,7 +370,9 @@
if (isfile(tmp2))
continue;
- err_cnt += pkg_do(dp->d_name);
+ if ((Flags & SHOW_ALL_PACKAGES)
+ || !is_automatic_installed(tmp2))
+ err_cnt += pkg_do(dp->d_name);
}
(void) closedir(dirp);
}
Index: info/pkg_info.1
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/info/pkg_info.1,v
retrieving revision 1.49
diff -u -r1.49 pkg_info.1
--- info/pkg_info.1 30 May 2005 13:10:14 -0000 1.49
+++ info/pkg_info.1 23 Oct 2005 20:01:47 -0000
@@ -17,7 +17,7 @@
.\"
.\" @(#)pkg_info.1
.\"
-.Dd May 30, 2005
+.Dd October 23, 2005
.Dt PKG_INFO 1
.Os
.Sh NAME
@@ -26,24 +26,14 @@
.Sh SYNOPSIS
.Nm
.Op Fl BbcDdFfhIikLmNnpqRrSsVv
-.Bk -words
.Op Fl e Ar package
-.Ek
-.Bk -words
.Op Fl K Ar pkg_dbdir
-.Ek
-.Bk -words
.Op Fl l Ar prefix
-.Ek
.Ar pkg-name ...
.Nm
-.Bk -words
-.Op Fl a Ar flags
-.Ek
+.Op Fl a
.Nm
-.Bk -words
.Op Fl Q Ar variable
-.Ek
.Ar pkg-name ...
.Sh DESCRIPTION
The
@@ -69,9 +59,17 @@
.Bl -tag -width indent
.It Fl a
Show information for all currently installed packages.
+By default, automatically installed packages (as dependencies
+of other packages) are not displayed.
.It Fl B
Show some of the important definitions used when building
-the binary package (the "Build information") for each package.
+the binary package (the
+.Dq Build information )
+for each package.
+Additionally, the variable
+.Ar automatic
+tells if a package was installed automatically
+as a dependency of another package.
.It Fl b
Show the
.Nx
Index: lib/Makefile
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/lib/Makefile,v
retrieving revision 1.23
diff -u -r1.23 Makefile
--- lib/Makefile 23 May 2004 02:24:52 -0000 1.23
+++ lib/Makefile 23 Oct 2005 20:01:47 -0000
@@ -4,8 +4,8 @@
MKPRIVATELIB= yes
LIB= install
-SRCS= file.c ftpio.c global.c lpkg.c pen.c pkgdb.c \
- plist.c str.c version.c path.c fexec.c
+SRCS= automatic.c file.c ftpio.c global.c lpkg.c pen.c \
+ pkgdb.c plist.c str.c version.c path.c fexec.c
version.o: version.h version.c
Index: lib/automatic.c
===================================================================
RCS file: lib/automatic.c
diff -N lib/automatic.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/automatic.c 23 Oct 2005 20:01:47 -0000
@@ -0,0 +1,83 @@
+/* $NetBSD$ */
+
+/*-
+ * Copyright (c) 2005 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD$");
+#endif
+
+#include <err.h>
+#include "lib.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+Boolean
+is_automatic_installed(const char *path)
+{
+ char filename[BUFSIZ];
+
+ (void)snprintf(filename, sizeof(filename), "%s/%s", path,
+ AUTOMATIC_FNAME);
+ return isfile(filename);
+}
+
+int
+mark_as_automatic_installed(const char *path, int value)
+{
+ char filename[BUFSIZ];
+ int fd;
+
+ (void)snprintf(filename, sizeof(filename), "%s/%s", path,
+ AUTOMATIC_FNAME);
+
+ if (value == 1) {
+ fd = open(filename, O_WRONLY|O_CREAT, 0644);
+ if (fd == -1) {
+ warn("error marking package `%s' as automatic", path);
+ return -1;
+ }
+ close(fd);
+ } else {
+ if (unlink(filename) < 0 && errno != ENOENT)
+ warn("error marking package `%s' as non-automatic",
+ path);
+ return -1;
+ }
+
+ return 0;
+}
Index: lib/lib.h
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/lib/lib.h,v
retrieving revision 1.76
diff -u -r1.76 lib.h
--- lib/lib.h 31 May 2005 22:29:41 -0000 1.76
+++ lib/lib.h 23 Oct 2005 20:01:47 -0000
@@ -115,6 +115,7 @@
};
/* The names of our "special" files */
+#define AUTOMATIC_FNAME "+AUTOMATIC"
#define CONTENTS_FNAME "+CONTENTS"
#define COMMENT_FNAME "+COMMENT"
#define DESC_FNAME "+DESC"
@@ -258,6 +259,11 @@
int fexec_skipempty(const char *, ...);
int fcexec(const char *, const char *, ...);
+/* automatically installed as dependency */
+
+Boolean is_automatic_installed(const char *);
+int mark_as_automatic_installed(const char *, int);
+
/* String */
char *get_dash_string(char **);
void str_lowercase(unsigned char *);
Index: lib/version.h
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/lib/version.h,v
retrieving revision 1.68
diff -u -r1.68 version.h
--- lib/version.h 18 Jul 2005 09:09:35 -0000 1.68
+++ lib/version.h 23 Oct 2005 20:01:47 -0000
@@ -33,6 +33,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
-#define PKGTOOLS_VERSION "20050718"
+#define PKGTOOLS_VERSION "20051023"
#endif /* _INST_LIB_VERSION_H_ */
--fUYQa+Pmc3FrFX/N--