- Add ability to handle bzip2-compressed packages;

- fix cosmetics to shut-up compiler in -pedantic mode (axe several unused vars
  and provide default clause in several switch() statements).

No response from:	-ports
This commit is contained in:
sobomax 2001-01-22 12:01:55 +00:00
parent 89713f84c0
commit a7de4cce1e
8 changed files with 79 additions and 26 deletions

View File

@ -249,6 +249,9 @@ extract_plist(char *home, Package *pkg)
case PLIST_IGNORE:
p = p->next;
break;
default:
break;
}
p = p->next;
}

View File

@ -168,7 +168,7 @@ main(int argc, char **argv)
usage();
}
/* Make sure the sub-execs we invoke get found */
setenv("PATH", "/sbin:/usr/sbin:/bin:/usr/bin", 1);
setenv("PATH", "/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin", 1);
/* Set a reasonable umask */
umask(022);

View File

@ -41,6 +41,7 @@ extern char *Origin;
extern char PlayPen[];
extern int Dereference;
extern int PlistOnly;
extern int UseBzip2;
void check_list(char *, Package *);
int pkg_perform(char **);

View File

@ -18,7 +18,7 @@ static const char rcsid[] =
#include "lib.h"
#include "create.h"
static char Options[] = "YNOhvf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:";
static char Options[] = "YNOhvyf:p:P:c:d:i:I:k:K:r:t:X:D:m:s:o:";
char *Prefix = NULL;
char *Comment = NULL;
@ -38,6 +38,7 @@ char *Origin = NULL;
char PlayPen[FILENAME_MAX];
int Dereference = FALSE;
int PlistOnly = FALSE;
int UseBzip2 = FALSE;
static void usage __P((void));
@ -134,6 +135,10 @@ main(int argc, char **argv)
Origin = optarg;
break;
case 'y':
UseBzip2 = FALSE;
break;
case '?':
default:
usage();
@ -167,7 +172,7 @@ static void
usage()
{
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
"usage: pkg_create [-YNOhv] [-P pkgs] [-p prefix] [-f contents] [-i iscript]",
"usage: pkg_create [-YNOhvy] [-P pkgs] [-p prefix] [-f contents] [-i iscript]",
" [-I piscript] [-k dscript] [-K pdscript] [-r rscript] ",
" [-t template] [-X excludefile] [-D displayfile] ",
" [-m mtreefile] [-o origin] -c comment -d description ",

View File

@ -70,14 +70,23 @@ pkg_perform(char **pkgs)
if (len > 4) {
if (!strcmp(&pkg[len - 4], ".tgz")) {
compress = TRUE;
UseBzip2 = FALSE;
pkg[len - 4] = '\0';
}
else if (!strcmp(&pkg[len - 4], ".tar")) {
compress = FALSE;
UseBzip2 = FALSE;
pkg[len - 4] = '\0';
}
else if ((len > 5) && (!strcmp(&pkg[len - 5], ".tbz2"))) {
compress = FALSE;
UseBzip2 = TRUE;
pkg[len - 5] = '\0';
}
}
if (compress)
if (UseBzip2)
suf = "tbz2";
else if (compress)
suf = "tgz";
else
suf = "tar";
@ -225,6 +234,7 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
int pipefds[2];
FILE *totar;
pid_t pid;
char *cname;
args[nargs++] = "tar"; /* argv[0] */
@ -236,8 +246,18 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
args[nargs++] = "-c";
args[nargs++] = "-f";
args[nargs++] = tball;
if (strchr(suffix, 'z')) /* Compress/gzip? */
args[nargs++] = "-z";
if (strchr(suffix, 'z')) { /* Compress/gzip/bzip2? */
if (UseBzip2) {
args[nargs++] = "-y";
cname = "bzip'd ";
}
else {
args[nargs++] = "-z";
cname = "gzip'd ";
}
} else {
cname = "";
}
if (Dereference)
args[nargs++] = "-h";
if (ExcludeFrom) {
@ -249,7 +269,7 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
args[nargs] = NULL;
if (Verbose)
printf("Creating gzip'd tar ball in '%s'\n", tball);
printf("Creating %star ball in '%s'\n", cname, tball);
/* Set up a pipe for passing the filenames, and fork off a tar process. */
if (pipe(pipefds) == -1) {

View File

@ -31,7 +31,7 @@
.Nd a utility for creating software package distributions
.Sh SYNOPSIS
.Nm
.Op Fl YNOhv
.Op Fl YNOhvy
.Op Fl P Ar pkgs
.Op Fl p Ar prefix
.Op Fl f Ar contents
@ -252,6 +252,21 @@ as location of the port from which package has been created in the
.Em "Ports Collection" .
It should be in the form
.Pa MASTERCATEGORY/PORTDIR .
.It Fl y
Use
.Xr bzip2 1
utility to compress package tarball instead of
.Xr gzip 1 .
Please note that this option is no-op if format of the resulting
archive is explicitly specified by the recognizeable suffix of
.Ar pkg-name .
Currently
.Nm
recognizes the following suffixes:
.Dq .tgz ,
.Dq .tar
and
.Dq .tbz2 .
.El
.Pp
.Sh PACKING LIST DETAILS

View File

@ -142,16 +142,13 @@ isURL(char *fname)
char *
fileGetURL(char *base, char *spec)
{
char host[HOSTNAME_MAX], file[FILENAME_MAX];
char pword[HOSTNAME_MAX + 40], *uname, *cp, *rp;
char *cp, *rp;
char fname[FILENAME_MAX];
char pen[FILENAME_MAX];
char buf[8192];
struct passwd *pw;
FILE *ftp;
pid_t tpid;
int pfd[2], pstat;
int i, status;
size_t r, w;
char *hint;
@ -248,6 +245,8 @@ fileFindByPath(char *base, char *fname)
{
static char tmp[FILENAME_MAX];
char *cp;
char *suffixes[] = {".tgz", ".tar", ".tbz2", NULL};
int i;
if (fexists(fname) && isfile(fname)) {
strcpy(tmp, fname);
@ -261,23 +260,26 @@ fileFindByPath(char *base, char *fname)
*cp = '\0'; /* chop name */
cp = strrchr(tmp, '/');
}
if (cp) {
*(cp + 1) = '\0';
strcat(cp, "All/");
strcat(cp, fname);
strcat(cp, ".tgz");
if (fexists(tmp))
return tmp;
}
if (cp)
for (i = 0; suffixes[i] != NULL; i++) {
*(cp + 1) = '\0';
strcat(cp, "All/");
strcat(cp, fname);
strcat(cp, suffixes[i]);
if (fexists(tmp))
return tmp;
}
}
cp = getenv("PKG_PATH");
while (cp) {
char *cp2 = strsep(&cp, ":");
snprintf(tmp, FILENAME_MAX, "%s/%s.tgz", cp2 ? cp2 : cp, fname);
if (fexists(tmp) && isfile(tmp))
return tmp;
for (i = 0; suffixes[i] != NULL; i++) {
snprintf(tmp, FILENAME_MAX, "%s/%s%s", cp2 ? cp2 : cp, fname, suffixes[i]);
if (fexists(tmp) && isfile(tmp))
return tmp;
}
}
return NULL;
}
@ -438,14 +440,18 @@ unpack(char *pkg, char *flist)
args[0] = '\0';
/*
* Figure out by a crude heuristic whether this or not this is probably
* compressed.
* compressed and whichever compression utility was used (gzip or bzip2).
*/
if (strcmp(pkg, "-")) {
cp = strrchr(pkg, '.');
if (cp) {
strcpy(suffix, cp + 1);
if (strchr(suffix, 'z') || strchr(suffix, 'Z'))
strcpy(args, "-z");
if (strchr(suffix, 'z') || strchr(suffix, 'Z')) {
if (strchr(suffix, 'b'))
strcpy(args, "-y");
else
strcpy(args, "-z");
}
}
}
else

View File

@ -447,6 +447,9 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
}
last_file = p->name;
break;
default:
break;
}
}
return fail;