summaryrefslogtreecommitdiff
path: root/bin/pax
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-02-07 19:43:11 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-02-07 19:43:11 +0000
commit97ef0f3652413ea840dad39de84ab3e8bca3f2f0 (patch)
treebd578a36c15a147422999efe654929f650e2132a /bin/pax
parent83fe112cdef1ff9a7ca42301c8254e7b5d565cf3 (diff)
Fix -T option and add support for -C option in the file pointed to
by -T ala GNU tar. Based on a patch from woods@proven.weird.com; Closes PR #1664
Diffstat (limited to 'bin/pax')
-rw-r--r--bin/pax/ftree.c6
-rw-r--r--bin/pax/options.c135
-rw-r--r--bin/pax/tar.145
3 files changed, 116 insertions, 70 deletions
diff --git a/bin/pax/ftree.c b/bin/pax/ftree.c
index f95dd8d03b8..1be7588a38a 100644
--- a/bin/pax/ftree.c
+++ b/bin/pax/ftree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftree.c,v 1.9 1998/06/09 07:28:41 deraadt Exp $ */
+/* $OpenBSD: ftree.c,v 1.10 2001/02/07 19:43:10 millert Exp $ */
/* $NetBSD: ftree.c,v 1.4 1995/03/21 09:07:21 cgd Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)ftree.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: ftree.c,v 1.9 1998/06/09 07:28:41 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: ftree.c,v 1.10 2001/02/07 19:43:10 millert Exp $";
#endif
#endif /* not lint */
@@ -171,7 +171,7 @@ ftree_add(str, chflg)
* simple check for bad args
*/
if ((str == NULL) || (*str == '\0')) {
- paxwarn(0, "Invalid file name arguement");
+ paxwarn(0, "Invalid file name argument");
return(-1);
}
diff --git a/bin/pax/options.c b/bin/pax/options.c
index cfabc071d2d..97a60014892 100644
--- a/bin/pax/options.c
+++ b/bin/pax/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.44 2001/02/05 00:32:12 deraadt Exp $ */
+/* $OpenBSD: options.c,v 1.45 2001/02/07 19:43:10 millert Exp $ */
/* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: options.c,v 1.44 2001/02/05 00:32:12 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: options.c,v 1.45 2001/02/07 19:43:10 millert Exp $";
#endif
#endif /* not lint */
@@ -607,6 +607,7 @@ tar_options(argc, argv)
register int c;
int fstdin = 0;
int Oflag = 0;
+ char *listfile = NULL;
/*
* Set default values.
@@ -617,7 +618,7 @@ tar_options(argc, argv)
* process option flags
*/
while ((c = getoldopt(argc, argv,
- "b:cef:hmopqruts:vwxzBC:HLOPXZ014578"))
+ "b:cef:hmopqruts:vwxzBC:HLOPT:XZ014578"))
!= -1) {
switch(c) {
case 'b':
@@ -762,6 +763,9 @@ tar_options(argc, argv)
*/
rmleadslash = 0;
break;
+ case 'T':
+ listfile = optarg;
+ break;
case 'X':
/*
* do not pass over mount points in the file system
@@ -806,8 +810,8 @@ tar_options(argc, argv)
else
listf = stdout;
- /* Traditional tar behaviour (pax wants to read filelist from stdin) */
- if ((act == ARCHIVE || act == APPND) && argc == 0)
+ /* Traditional tar behaviour (pax wants to read file list from stdin) */
+ if ((act == ARCHIVE || act == APPND) && argc == 0 && listfile == NULL)
exit(0);
/*
@@ -830,7 +834,44 @@ tar_options(argc, argv)
default:
{
int sawpat = 0;
+ int cdmode = 0;
+
+ if (listfile) {
+ FILE *fp;
+ char *str;
+
+ if (strcmp(listfile, "-") == 0)
+ fp = stdin;
+ else if ((fp = fopen(listfile, "r")) == NULL) {
+ paxwarn(1, "Unable to open file '%s' for read", listfile);
+ tar_usage();
+ }
+ while ((str = getline(fp)) != NULL) {
+ if (strcmp(str, "-C") == 0) {
+ cdmode = 1;
+ continue;
+ }
+ /*
+ * If last line was "-C" then
+ * this line has the dir, else
+ * we have a pattern.
+ */
+ if (cdmode)
+ chdname = str;
+ else if (pat_add(str, chdname) < 0)
+ tar_usage();
+ else
+ sawpat = 1;
+ cdmode = 0;
+ }
+ if (strcmp(listfile, "-") != 0)
+ fclose(fp);
+ if (getline_error) {
+ paxwarn(1, "Problem with file '%s'", listfile);
+ tar_usage();
+ }
+ }
while (*argv != NULL) {
if (strcmp(*argv, "-C") == 0) {
if(*++argv == NULL)
@@ -839,34 +880,9 @@ tar_options(argc, argv)
continue;
}
- if (strcmp(*argv, "-T") == 0) {
- FILE *fp;
- char *str;
-
- if (*++argv == NULL)
- break;
-
- if ((fp = fopen(*argv, "r")) == NULL) {
- paxwarn(1, "Unable to open file '%s' for read", *argv);
- tar_usage();
- }
- while ((str = getline(fp)) != NULL) {
- if (pat_add(str, chdname) < 0)
- tar_usage();
- sawpat++;
- }
- fclose(fp);
- if (getline_error) {
- paxwarn(1, "Problem with file '%s'", *argv);
- tar_usage();
- }
- argv++;
-
- continue;
- }
if (pat_add(*argv++, chdname) < 0)
tar_usage();
- sawpat++;
+ sawpat = 1;
}
/*
* if patterns were added, we are doing chdir()
@@ -884,6 +900,35 @@ tar_options(argc, argv)
tar_usage();
}
+ if (listfile) {
+ FILE *fp;
+ char *str;
+ int cdmode = 0;
+
+ if (strcmp(listfile, "-") == 0)
+ fp = stdin;
+ else if ((fp = fopen(listfile, "r")) == NULL) {
+ paxwarn(1, "Unable to open file '%s' for read",
+ listfile);
+ tar_usage();
+ }
+ while ((str = getline(fp)) != NULL) {
+ if (strcmp(str, "-C") == 0) {
+ cdmode = 1;
+ continue;
+ }
+
+ if (ftree_add(str, cdmode) < 0)
+ tar_usage();
+ cdmode = 0;
+ }
+ if (strcmp(listfile, "-") != 0)
+ fclose(fp);
+ if (getline_error) {
+ paxwarn(1, "Problem with file '%s'", listfile);
+ tar_usage();
+ }
+ }
while (*argv != NULL) {
if (strcmp(*argv, "-C") == 0) {
if (*++argv == NULL)
@@ -893,30 +938,6 @@ tar_options(argc, argv)
continue;
}
- if (strcmp(*argv, "-T") == 0) {
- FILE *fp;
- char *str;
-
- if (*++argv == NULL)
- break;
-
- if ((fp = fopen(*argv, "r")) == NULL) {
- paxwarn(1, "Unable to open file '%s' for read", *argv);
- tar_usage();
- }
- while ((str = getline(fp)) != NULL) {
- if (ftree_add(str, 0) < 0)
- tar_usage();
- }
- fclose(fp);
- if (getline_error) {
- paxwarn(1, "Problem with file '%s'", *argv);
- tar_usage();
- }
- argv++;
-
- continue;
- }
if (ftree_add(*argv++, 0) < 0)
tar_usage();
}
@@ -1581,9 +1602,9 @@ void
tar_usage()
#endif
{
- (void)fputs("usage: tar [-]{txru}[cevfbmopqswzBHLPXZ014578] [tapefile] ",
+ (void)fputs("usage: tar [-]{crtux}[-befhmopqvwzHLOPXZ014578] [archive] ",
stderr);
- (void)fputs("[blocksize] [replstr] [-C directory] [-T file] file1 file2...\n",
+ (void)fputs("[blocksize] [-C directory] [-T file] [-s replstr] [file ...]\n",
stderr);
exit(1);
}
diff --git a/bin/pax/tar.1 b/bin/pax/tar.1
index 87cd8dd29d2..3f64a9eb818 100644
--- a/bin/pax/tar.1
+++ b/bin/pax/tar.1
@@ -27,9 +27,9 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $OpenBSD: tar.1,v 1.30 2001/02/07 19:04:15 millert Exp $
+.\" $OpenBSD: tar.1,v 1.31 2001/02/07 19:43:10 millert Exp $
.\"
-.Dd June 11, 1996
+.Dd February 7, 2001
.Dt TAR 1
.Os
.Sh NAME
@@ -46,16 +46,16 @@
.Op Fl C Ar directory
.Op Fl T Ar file
.Op Fl s Ar replstr
-.Ar file1
-.Op Ar file2 ...
+.Op Ar file ...
.Sh DESCRIPTION
The
.Nm
command creates, adds files to, or extracts files from an
-archive file in \*Qtar\*U format.
-A tar archive is often
-stored on a magnetic tape, but can be a floppy or a regular
-disk file.
+archive file in
+.Dq tar
+format.
+A tar archive is often stored on a magnetic tape, but can be
+stored equally well on a floppy, CD-ROM, or in a regular disk file.
.Pp
One of the following flags must be present:
.Bl -tag -width Ar
@@ -197,6 +197,9 @@ following files.
When extracting, files will be extracted into
the specified directory; when creating, the specified files will be matched
from the directory.
+This argument and its parameter may also appear in a file list specified by
+.Fl T ,
+but in this case it should be separated by a newline instead of whitespace.
.It Fl H
Follow symlinks given on command line only.
.It Fl L
@@ -207,8 +210,13 @@ Do not strip leading slashes
from pathnames.
The default is to strip leading slashes.
.It Fl T Ar file
-This is a positional argument which reads the names of files to archive or
-extract from the given file.
+Read the names of files to archive or extract from the given file, one
+per line.
+A line may also specify the positional argument
+.Dq Fl C
+with the
+.Ar directory
+listed on the next line.
.It Fl X
Do not cross mount points in the file system.
.It Fl Z
@@ -277,3 +285,20 @@ Default tape device to use instead of
.Xr pax 1
.Sh AUTHORS
Keith Muller at the University of California, San Diego.
+.Sh HISTORY
+A
+.Nm
+command first appeared in
+.At v7 .
+.Sh CAVEATS
+The
+.Fl L
+flag is not portable to other versions of
+.Nm
+where it may have a different meaning.
+.Pp
+Unlike some versions of
+.Nm tar ,
+when the
+.Fl T
+flag is specified other files may still be listed on the command line.