summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install
diff options
context:
space:
mode:
authorkeramida <keramida@FreeBSD.org>2008-05-27 05:10:54 +0000
committerkeramida <keramida@FreeBSD.org>2008-05-27 05:10:54 +0000
commitac192fc2f13824789c65f651efe43dc36ce04ecb (patch)
tree278d6e0261b39f00f8600e1d2ed92581cb321d23 /usr.sbin/pkg_install
parent456ca43f89f09bbc298c6cb81599ad3859b84efb (diff)
downloadFreeBSD-src-ac192fc2f13824789c65f651efe43dc36ce04ecb.zip
FreeBSD-src-ac192fc2f13824789c65f651efe43dc36ce04ecb.tar.gz
Add a -n option to pkg_create(1), to inhibit duplicate work.
When run without this option, multiple runs of `pkg_create -Rb' will recreate common packages multiple times. This can take a lot of time for large packages. With the -n option `pkg_create -b' checks with stat(2) and skips packages that already exist. Note that this may *not* be safe of the existing output file is not really a package, or if it has been corrupted, modified or otherwise tinkered with between subsequent pkg_create runs. For this and POLA reasons, the default behavior is to *rebuild* the packages, and the -n option can be used when we know it is `safe' to run in no-regenerate mode. Inspired by: A post to freebsd-questions by Matthias Apitz &lt; matthias.apitz at oclc.org &gt; Reviewed by: marcus, flz Approved by: marcus MFC after: 2 weeks
Diffstat (limited to 'usr.sbin/pkg_install')
-rw-r--r--usr.sbin/pkg_install/create/create.h1
-rw-r--r--usr.sbin/pkg_install/create/main.c9
-rw-r--r--usr.sbin/pkg_install/create/perform.c13
-rw-r--r--usr.sbin/pkg_install/create/pkg_create.124
4 files changed, 42 insertions, 5 deletions
diff --git a/usr.sbin/pkg_install/create/create.h b/usr.sbin/pkg_install/create/create.h
index 9450170..310aba0 100644
--- a/usr.sbin/pkg_install/create/create.h
+++ b/usr.sbin/pkg_install/create/create.h
@@ -46,6 +46,7 @@ extern char PlayPen[];
extern int Dereference;
extern int PlistOnly;
extern int Recursive;
+extern int Regenerate;
enum zipper {NONE, GZIP, BZIP, BZIP2 };
extern enum zipper Zipper;
diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c
index c35cfd6..ea15b91 100644
--- a/usr.sbin/pkg_install/create/main.c
+++ b/usr.sbin/pkg_install/create/main.c
@@ -16,7 +16,7 @@ __FBSDID("$FreeBSD$");
#include "lib.h"
#include "create.h"
-static char Options[] = "EGYNORhjvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:";
+static char Options[] = "EGYNnORhjvxyzf:p:P:C:c:d:i:I:k:K:r:t:X:D:m:s:S:o:b:";
match_t MatchType = MATCH_GLOB;
char *Prefix = NULL;
@@ -41,6 +41,7 @@ char PlayPen[FILENAME_MAX];
int Dereference = FALSE;
int PlistOnly = FALSE;
int Recursive = FALSE;
+int Regenerate = TRUE;
#if defined(__FreeBSD_version) && __FreeBSD_version >= 500039
enum zipper Zipper = BZIP2;
#else
@@ -192,6 +193,10 @@ main(int argc, char **argv)
Recursive = TRUE;
break;
+ case 'n':
+ Regenerate = FALSE;
+ break;
+
case '?':
default:
usage();
@@ -228,7 +233,7 @@ static void
usage()
{
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
-"usage: pkg_create [-YNOhjvyz] [-C conflicts] [-P pkgs] [-p prefix]",
+"usage: pkg_create [-YNOhjnvyz] [-C conflicts] [-P pkgs] [-p prefix]",
" [-i iscript] [-I piscript] [-k dscript] [-K pdscript]",
" [-r rscript] [-s srcdir] [-S basedir]",
" [-t template] [-X excludefile]",
diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c
index 77ec1f2..505826e 100644
--- a/usr.sbin/pkg_install/create/perform.c
+++ b/usr.sbin/pkg_install/create/perform.c
@@ -28,6 +28,8 @@ __FBSDID("$FreeBSD$");
#include <libgen.h>
#include <signal.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <sys/syslimits.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -336,6 +338,7 @@ pkg_perform(char **pkgs)
static void
make_dist(const char *homedir, const char *pkg, const char *suff, Package *plist)
{
+ struct stat sb;
char tball[FILENAME_MAX];
PackingList p;
int ret;
@@ -355,6 +358,16 @@ make_dist(const char *homedir, const char *pkg, const char *suff, Package *plist
else
snprintf(tball, FILENAME_MAX, "%s/%s.%s", homedir, pkg, suff);
+ /*
+ * If the package tarball exists already, and we are running in `no
+ * clobber' mode, skip this package.
+ */
+ if (stat(tball, &sb) == 0 && Regenerate == FALSE) {
+ if (Verbose)
+ printf("Skipping package '%s'. It already exists.\n", tball);
+ return;
+ }
+
args[nargs++] = "-c";
args[nargs++] = "-f";
args[nargs++] = tball;
diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1
index 6fb6d58..a65cfaf 100644
--- a/usr.sbin/pkg_install/create/pkg_create.1
+++ b/usr.sbin/pkg_install/create/pkg_create.1
@@ -23,7 +23,7 @@
.\" [jkh] Took John's changes back and made some additional extensions for
.\" better integration with FreeBSD's new ports collection.
.\"
-.Dd November 8, 2005
+.Dd May 27, 2008
.Dt PKG_CREATE 1
.Os
.Sh NAME
@@ -31,7 +31,7 @@
.Nd a utility for creating software package distributions
.Sh SYNOPSIS
.Nm
-.Op Fl YNOhjvyz
+.Op Fl YNOhjnvyz
.Op Fl C Ar conflicts
.Op Fl P Ar pkgs
.Op Fl p Ar prefix
@@ -52,7 +52,7 @@
.Fl f Ar packlist
.Ar pkg-filename
.Nm
-.Op Fl EGYNRhvxy
+.Op Fl EGYNRhnvxy
.Fl b Ar pkg-name
.Op Ar pkg-filename
.Sh DESCRIPTION
@@ -350,6 +350,24 @@ Use extended (modern) regular expressions for
.It Fl G
Use exact matching for
.Ar pkg-name .
+.It Fl n
+Run in
+.Dq no clobber
+mode.
+If a package tarball exists, the
+.Nm
+utility will not overwrite it.
+This is useful, for example, when multiple packages are saved with
+several consecutive runs of
+.Nm
+with the
+.Fl Rb
+options.
+Saving common dependencies multiple times would do a lot of duplicate
+work in this case.
+The
+.Fl n
+option avoids repackaging common dependencies multiple times.
.El
.Sh PACKING LIST DETAILS
The
OpenPOWER on IntegriCloud