Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/pkg_install/lib allow bzip2 support to work on earl...



details:   https://anonhg.NetBSD.org/src/rev/24ed4156899c
branches:  trunk
changeset: 545537:24ed4156899c
user:      grant <grant%NetBSD.org@localhost>
date:      Thu Apr 10 16:25:25 2003 +0000

description:
allow bzip2 support to work on earlier systems where tar has no -j
option, including NetBSD 1.5 and 1.6. noted by wiz.

also handle tar.gz, tar.bz2 and .tar filenames, and bomb with a useful
error if we don't know to handle a file.

diffstat:

 usr.sbin/pkg_install/lib/file.c |  27 ++++++++++++++++-----------
 usr.sbin/pkg_install/lib/lib.h  |  11 ++++++++++-
 2 files changed, 26 insertions(+), 12 deletions(-)

diffs (75 lines):

diff -r 3f82dae13c3a -r 24ed4156899c usr.sbin/pkg_install/lib/file.c
--- a/usr.sbin/pkg_install/lib/file.c   Thu Apr 10 16:12:38 2003 +0000
+++ b/usr.sbin/pkg_install/lib/file.c   Thu Apr 10 16:25:25 2003 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: file.c,v 1.59 2003/04/10 05:08:55 grant Exp $  */
+/*     $NetBSD: file.c,v 1.60 2003/04/10 16:25:25 grant Exp $  */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
 #else
-__RCSID("$NetBSD: file.c,v 1.59 2003/04/10 05:08:55 grant Exp $");
+__RCSID("$NetBSD: file.c,v 1.60 2003/04/10 16:25:25 grant Exp $");
 #endif
 #endif
 
@@ -526,18 +526,23 @@
 unpack(const char *pkg, const char *flist)
 {
        char    args[10] = "-";
-       const char *suffix;
+       const char *decompress_cmd;
+       const char *suf;
 
        if (!IS_STDIN(pkg)) {
-               suffix = suffix_of(pkg);
-               if (!strcmp(suffix, "tbz"))
-                       strcat(args, "j");
-               else if (!strcmp(suffix, "tgz"))
-                       strcat(args, "z");
+               suf = suffix_of(pkg);
+               if (!strcmp(suf, "tbz") || !strcmp(suf, "bz2"))
+                       decompress_cmd = BZIP2_CMD " -c -d";
+               else if (!strcmp(suf, "tgz") || !strcmp(suf, "gz"))
+                       decompress_cmd = GZIP_CMD " -c -d";
+               else if (!strcmp(suf, "tar"))
+                       decompress_cmd = "cat";
+               else
+                       errx(EXIT_FAILURE, "don't know how to decompress %s, sorry", pkg);
        } else
-               strcat(args, "z");
-       strcat(args, "xpf");
-       if (vsystem("%s %s %s %s", TAR_CMD, args, pkg, flist ? flist : "")) {
+               decompress_cmd = GZIP_CMD " -c -d";
+       strcat(args, "xpf -");
+       if (vsystem("%s %s | %s %s %s", decompress_cmd, pkg, TAR_CMD, args, flist ? flist : "")) {
                warnx("%s extract of %s failed!", TAR_CMD, pkg);
                return 1;
        }
diff -r 3f82dae13c3a -r 24ed4156899c usr.sbin/pkg_install/lib/lib.h
--- a/usr.sbin/pkg_install/lib/lib.h    Thu Apr 10 16:12:38 2003 +0000
+++ b/usr.sbin/pkg_install/lib/lib.h    Thu Apr 10 16:25:25 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.49 2003/03/15 20:49:27 agc Exp $ */
+/* $NetBSD: lib.h,v 1.50 2003/04/10 16:25:25 grant Exp $ */
 
 /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
 
@@ -63,6 +63,15 @@
 #define TAR_CMD        "tar"
 #endif
 
+/* Define gzip and bzip2, used to unpack binary packages */
+#ifndef GZIP_CMD
+#define GZIP_CMD "gzip"
+#endif
+
+#ifndef BZIP2_CMD
+#define BZIP2_CMD "bzip2"
+#endif
+
 /* Define ftp as a string, in case the ftp client is called something else */
 #ifndef FTP_CMD
 #define FTP_CMD "ftp"



Home | Main Index | Thread Index | Old Index