bin/77082: src/usr.sbin/pkg_install - Add 3 new macros to clean
pkg-plist
Florent Thoumie
flz at xbsd.org
Fri Feb 4 08:00:41 PST 2005
The following reply was made to PR bin/77082; it has been noted by GNATS.
From: Florent Thoumie <flz at xbsd.org>
To: FreeBSD-gnats-submit at FreeBSD.org, freebsd-bugs at FreeBSD.org
Cc: hq at FreeBSD.org
Subject: Re: bin/77082: src/usr.sbin/pkg_install - Add 3 new macros to clean
pkg-plist
Date: Fri, 04 Feb 2005 16:58:34 +0100
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig94AF4F6B51667C03D3708100
Content-Type: multipart/mixed;
boundary="------------000308030407090406080400"
This is a multi-part message in MIME format.
--------------000308030407090406080400
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Here is a new version.
I've renamed @dirrmie by @dirrmtry, which is more self-explanatory.
@cpin and @rmiu have been replaced by @conf.
@conf %%EXAMPLESDIR%%/etc/foo.conf etc/foo.conf
is equivalent to :
@unexec cmp -s %D/%%EXAMPLESDIR%%/etc/foo.conf %D/etc/foo.conf && rm -f %D/etc/foo.conf
%%EXAMPLESDIR%%/etc/foo.conf
@exec [ -f %B/foo.conf ] || cp %B/%f %B/foo.conf
--------------000308030407090406080400
Content-Type: text/plain;
name="pkg_install-v2.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="pkg_install-v2.diff"
diff -ruN pkg_install.orig/add/extract.c pkg_install/add/extract.c
--- pkg_install.orig/add/extract.c Wed Jul 28 09:19:15 2004
+++ pkg_install/add/extract.c Fri Feb 4 14:51:25 2005
@@ -136,7 +136,8 @@
/* Do it */
while (p) {
- char cmd[FILENAME_MAX];
+ char cmd[FILENAME_MAX], *name;
+ char tmp[FILENAME_MAX], tmp2[FILENAME_MAX];
switch(p->type) {
case PLIST_NAME:
@@ -145,6 +146,14 @@
printf("extract: Package name is %s\n", p->name);
break;
+ case PLIST_CONF:
+ if (!(name = strchr(p->name, ' ')))
+ {
+ warnx("missing either configuration file name or instance name");
+ }
+ *name++ = '\0';
+ /* FALLTHROUGH */
+
case PLIST_FILE:
last_file = p->name;
if (Verbose)
@@ -209,6 +218,26 @@
perm_count += add_count;
}
}
+
+ if (p->type != PLIST_CONF)
+ break;
+
+ sprintf(tmp, "%s/%s", Directory, name);
+ sprintf(tmp2, "%s/%s", Directory, p->name);
+ /*PUSHOUT(Directory);*/
+ if (!fexists(tmp2)) {
+ warnx("file '%s' does not exist!\n"
+ "this packing list is incorrect - ignoring instanciation request", tmp2);
+ }
+ else if (!fexists(tmp)) {
+ if (Verbose)
+ printf("Installing '%s' in '%s' (non-existent)\n", tmp2, tmp);
+ if (!Fake && vsystem("cp %s %s", tmp2, tmp)) {
+ errx(2, "%s: unable to copy '%s' to '%s'", __func__, p->name,
+ tmp2, tmp);
+ }
+ }
+ last_file = p->name;
break;
case PLIST_CWD:
diff -ruN pkg_install.orig/create/perform.c pkg_install/create/perform.c
--- pkg_install.orig/create/perform.c Wed Jul 28 09:19:15 2004
+++ pkg_install/create/perform.c Fri Feb 4 15:47:36 2005
@@ -310,6 +310,7 @@
FILE *totar;
pid_t pid;
const char *cname;
+ char *tmp;
args[nargs++] = "tar"; /* argv[0] */
@@ -393,6 +394,13 @@
for (p = plist->head; p; p = p->next) {
if (p->type == PLIST_FILE)
fprintf(totar, "%s\n", p->name);
+ if (p->type == PLIST_CONF)
+ {
+ tmp = strchr(p->name, ' ');
+ *tmp = '\0';
+ fprintf(totar, "%s\n", p->name);
+ *tmp = ' ';
+ }
else if (p->type == PLIST_CWD && BaseDir && p->name && p->name[0] == '/')
fprintf(totar, "-C\n%s%s\n", BaseDir, p->name);
else if (p->type == PLIST_CWD || p->type == PLIST_SRC)
diff -ruN pkg_install.orig/create/pkg_create.1 pkg_install/create/pkg_create.1
--- pkg_install.orig/create/pkg_create.1 Sat Jul 3 01:12:52 2004
+++ pkg_install/create/pkg_create.1 Fri Feb 4 15:53:25 2005
@@ -504,6 +504,21 @@
The
.Pa name
directory will not be removed unless it is empty.
+.It Cm @dirrmtry Ar name
+Same as
+.Cm @dirrm ,
+but there will be no error message nor warning if the directory is not
+empty.
+.It Cm @conf Ar name Ar instance
+Declare file
+.Pa name
+to be considered as a sample configuration file. At install time,
+.Pa instance
+is copied from
+.Pa name
+if it does not exist yet.
+.Pa instance
+will be also removed at deinstall time if it has not changed.
.It Cm @mtree Ar name
Declare
.Pa name
diff -ruN pkg_install.orig/create/pl.c pkg_install/create/pl.c
--- pkg_install.orig/create/pl.c Tue Jun 29 21:06:41 2004
+++ pkg_install/create/pl.c Fri Feb 4 15:40:43 2005
@@ -65,6 +65,7 @@
const char *there = NULL;
char name[FILENAME_MAX];
PackingList p;
+ char *tmp = NULL;
for (p = pkg->head; p != NULL; p = p->next)
switch (p->type) {
@@ -80,12 +81,19 @@
there = p->name;
break;
+ case PLIST_CONF:
case PLIST_FILE:
+ if (p->type == PLIST_CONF && (tmp = strchr(p->name, ' ')))
+ *tmp = '\0';
+
+ else tmp = p->name;
if (there)
snprintf(name, sizeof(name), "%s/%s", there, p->name);
else
snprintf(name, sizeof(name), "%s%s/%s",
BaseDir && where && where[0] == '/' ? BaseDir : "", where, p->name);
+ if (p->type == PLIST_CONF && tmp)
+ *tmp = ' ';
add_cksum(pkg, p, name);
break;
diff -ruN pkg_install.orig/delete/pkg_delete.1 pkg_install/delete/pkg_delete.1
--- pkg_install.orig/delete/pkg_delete.1 Sat Jul 3 01:12:52 2004
+++ pkg_install/delete/pkg_delete.1 Fri Feb 4 15:53:51 2005
@@ -60,6 +60,8 @@
.Cm @mode
(check for setuid),
.Cm @dirrm ,
+.Cm @dirrmtry ,
+.Cm @conf ,
.Cm @exec ,
and
.Cm @unexec
diff -ruN pkg_install.orig/info/show.c pkg_install/info/show.c
--- pkg_install.orig/info/show.c Mon May 26 19:06:05 2003
+++ pkg_install/info/show.c Fri Feb 4 15:54:33 2005
@@ -179,6 +179,14 @@
printf(Quiet ? "@dirrm %s\n" : "\tDeinstall directory remove: %s\n", p->name);
break;
+ case PLIST_DIR_RM_TRY:
+ printf(Quiet ? "@dirrmtry %s\n" : "\tDeinstall directory remove (don't issue warning): %s\n", p->name);
+ break;
+
+ case PLIST_CONF:
+ printf(Quiet ? "@conf %s\n" : "\tConfiguration file (and instance if non-existent): %s\n", p->name);
+ break;
+
case PLIST_OPTION:
printf(Quiet ? "@option %s\n" :
"\tOption \"%s\" controlling package installation behaviour\n",
diff -ruN pkg_install.orig/lib/lib.h pkg_install/lib/lib.h
--- pkg_install.orig/lib/lib.h Tue Jan 4 17:18:55 2005
+++ pkg_install/lib/lib.h Fri Feb 4 15:56:26 2005
@@ -108,7 +108,8 @@
PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT, PLIST_IGNORE,
PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
PLIST_PKGDEP, PLIST_CONFLICTS, PLIST_MTREE, PLIST_DIR_RM,
- PLIST_IGNORE_INST, PLIST_OPTION, PLIST_ORIGIN, PLIST_DEPORIGIN
+ PLIST_DIR_RM_TRY, PLIST_CONF, PLIST_IGNORE_INST, PLIST_OPTION,
+ PLIST_ORIGIN, PLIST_DEPORIGIN
};
typedef enum _plist_t plist_t;
diff -ruN pkg_install.orig/lib/plist.c pkg_install/lib/plist.c
--- pkg_install.orig/lib/plist.c Wed Jul 28 09:19:15 2004
+++ pkg_install/lib/plist.c Fri Feb 4 15:43:33 2005
@@ -247,6 +247,10 @@
return PLIST_MTREE;
else if (!strcmp(cmd, "dirrm"))
return PLIST_DIR_RM;
+ else if (!strcmp(cmd, "dirrmtry"))
+ return PLIST_DIR_RM_TRY;
+ else if (!strcmp(cmd, "conf"))
+ return PLIST_CONF;
else if (!strcmp(cmd, "option"))
return PLIST_OPTION;
else
@@ -378,6 +382,14 @@
fprintf(fp, "%cdirrm %s\n", CMD_CHAR, plist->name);
break;
+ case PLIST_DIR_RM_TRY:
+ fprintf(fp, "%cdirrmtry %s\n", CMD_CHAR, plist->name);
+ break;
+
+ case PLIST_CONF:
+ fprintf(fp, "%cconf %s\n", CMD_CHAR, plist->name);
+ break;
+
case PLIST_OPTION:
fprintf(fp, "%coption %s\n", CMD_CHAR, plist->name);
break;
@@ -413,7 +425,7 @@
const char *Where = ".", *last_file = "";
Boolean fail = SUCCESS;
Boolean preserve;
- char tmp[FILENAME_MAX], *name = NULL;
+ char tmp[FILENAME_MAX], tmp2[FILENAME_MAX], *name = NULL;
preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;
for (p = pkg->head; p; p = p->next) {
@@ -442,6 +454,38 @@
}
break;
+ case PLIST_CONF:
+ if (!(name = strchr(p->name, ' ')))
+ {
+ warnx("missing either configuration file name or instance name");
+ fail = FAIL;
+ }
+ *name++ = '\0';
+ sprintf(tmp, "%s/%s", Where, name);
+ sprintf(tmp2, "%s/%s", Where, p->name);
+ if (!fexists(tmp) || !fexists(tmp2)) {
+ warnx("specified file '%s' or '%s' does not exist!\n"
+ "this packing list is incorrect - ignoring delete request", tmp, tmp2);
+ }
+ else if (p->next && p->next->type == PLIST_COMMENT && !strncmp(p->next->name, "MD5:", 4)) {
+ char *cp = NULL, buf[33];
+ cp = MD5File(tmp, buf);
+
+ if (cp != NULL) {
+ /* Mismatch? */
+ if (!strcmp(cp, p->next->name + 4)) {
+
+ if (Verbose)
+ printf("Delete file %s (unchanged)\n", tmp);
+ if (!Fake && vsystem("%s %s %s", REMOVE_CMD, (ign_err ? "-f" : ""), tmp)) {
+ warnx("unable to remove file '%s'", tmp);
+ fail = FAIL;
+ }
+ }
+ }
+ }
+ /* FALLTHROUGH */
+
case PLIST_FILE:
last_file = p->name;
sprintf(tmp, "%s/%s", Where, p->name);
@@ -500,6 +544,7 @@
break;
case PLIST_DIR_RM:
+ case PLIST_DIR_RM_TRY:
sprintf(tmp, "%s/%s", Where, p->name);
if (!isdir(tmp) && fexists(tmp)) {
warnx("cannot delete specified directory '%s' - it is a file!\n"
@@ -508,7 +553,7 @@
else {
if (Verbose)
printf("Delete directory %s\n", tmp);
- if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) {
+ if (!Fake && delete_hierarchy(tmp, ign_err, FALSE) && p->type != PLIST_DIR_RM_TRY) {
warnx("unable to completely remove directory '%s'", tmp);
fail = FAIL;
}
--------------000308030407090406080400
Content-Type: text/plain;
name="dummy-1.1.shar"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="dummy-1.1.shar"
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# dummy
# dummy/Makefile
# dummy/pkg-descr
# dummy/pkg-plist
#
echo c - dummy
mkdir -p dummy > /dev/null 2>&1
echo x - dummy/Makefile
sed 's/^X//' >dummy/Makefile << 'END-of-dummy/Makefile'
XPORTNAME= dummy
XPORTVERSION= 1.1
XCATEGORIES= misc
XDISTFILES=
X
XMAINTAINER= ports at FreeBSD.org
XCOMMENT= Dummy port
X
XCONFDIR= ${EXAMPLESDIR}/etc
XNO_BUILD= yes
X
Xdo-install:
X ${MKDIR} ${CONFDIR}
X ${INSTALL_DATA} ${.CURDIR}/Makefile ${CONFDIR}/Makefile
X [ ! -f ${PREFIX}/etc/Makefile ] || ${INSTALL_DATA} ${.CURDIR}/Makefile ${PREFIX}/etc/Makefile
X
X.include <bsd.port.mk>
END-of-dummy/Makefile
echo x - dummy/pkg-descr
sed 's/^X//' >dummy/pkg-descr << 'END-of-dummy/pkg-descr'
XThis is a dummy port, for testing purposes.
X
XWWW: http://www.freebsd.org/
X
X- Florent Thoumie
Xflz at xbsd.org
END-of-dummy/pkg-descr
echo x - dummy/pkg-plist
sed 's/^X//' >dummy/pkg-plist << 'END-of-dummy/pkg-plist'
X at conf %%EXAMPLESDIR%%/etc/Makefile etc/Makefile
X at dirrmtry %%EXAMPLESDIR%%/etc
X at dirrmtry %%EXAMPLESDIR%%
END-of-dummy/pkg-plist
exit
--------------000308030407090406080400--
--------------enig94AF4F6B51667C03D3708100
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (FreeBSD)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCA5uwMxEkbVFH3PQRAimcAJ0ZWjDBlTMBW+td95vuqyi+LuPDrwCgjWBO
thN0YQY/jXX7OCdSFJgXmC8=
=xpXp
-----END PGP SIGNATURE-----
--------------enig94AF4F6B51667C03D3708100--
More information about the freebsd-bugs
mailing list