summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorThorsten Lockert <tholo@cvs.openbsd.org>1997-03-02 09:46:50 +0000
committerThorsten Lockert <tholo@cvs.openbsd.org>1997-03-02 09:46:50 +0000
commitba543da8d049867a1a178db878ec6565b671d15a (patch)
treed1642bd96420ce8fd6505ac92e030b13ac81e10d /bin
parent322646ef055f316e0cc138add35c58316a4de863 (diff)
More complete cpio(1) emulation
Diffstat (limited to 'bin')
-rw-r--r--bin/pax/cpio.15
-rw-r--r--bin/pax/extern.h3
-rw-r--r--bin/pax/file_subs.c10
-rw-r--r--bin/pax/options.c47
-rw-r--r--bin/pax/pax.c5
5 files changed, 54 insertions, 16 deletions
diff --git a/bin/pax/cpio.1 b/bin/pax/cpio.1
index f6af9140ece..75ca1ce6f7d 100644
--- a/bin/pax/cpio.1
+++ b/bin/pax/cpio.1
@@ -27,7 +27,7 @@
.\" (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: cpio.1,v 1.1 1997/02/20 06:54:33 tholo Exp $
+.\" $OpenBSD: cpio.1,v 1.2 1997/03/02 09:46:40 tholo Exp $
.\"
.Dd February 16, 1997
.Dt CPIO 1
@@ -261,9 +261,6 @@ specific archive format specification.
.Xr pax 1 ,
.Xr tar 1
.Sh BUGS
-The
-.Fl d
-option is the default and cannot be turned off.
The
.Fl s
and
diff --git a/bin/pax/extern.h b/bin/pax/extern.h
index 1bedec50087..2e3fea87f98 100644
--- a/bin/pax/extern.h
+++ b/bin/pax/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.10 1997/02/27 23:32:57 michaels Exp $ */
+/* $OpenBSD: extern.h,v 1.11 1997/03/02 09:46:43 tholo Exp $ */
/* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */
/*-
@@ -229,6 +229,7 @@ extern int Zflag;
extern int vfpart;
extern int patime;
extern int pmtime;
+extern int nodirs;
extern int pmode;
extern int pids;
extern int exit_val;
diff --git a/bin/pax/file_subs.c b/bin/pax/file_subs.c
index 6b9e80607d8..9828d8cf8dc 100644
--- a/bin/pax/file_subs.c
+++ b/bin/pax/file_subs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file_subs.c,v 1.4 1997/01/26 10:33:22 downsj Exp $ */
+/* $OpenBSD: file_subs.c,v 1.5 1997/03/02 09:46:45 tholo Exp $ */
/* $NetBSD: file_subs.c,v 1.4 1995/03/21 09:07:18 cgd Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)file_subs.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: file_subs.c,v 1.4 1997/01/26 10:33:22 downsj Exp $";
+static char rcsid[] = "$OpenBSD: file_subs.c,v 1.5 1997/03/02 09:46:45 tholo Exp $";
#endif
#endif /* not lint */
@@ -126,7 +126,7 @@ file_creat(arcn)
file_mode)) >= 0)
break;
oerrno = errno;
- if (chk_path(arcn->name,arcn->sb.st_uid,arcn->sb.st_gid) < 0) {
+ if (nodirs || chk_path(arcn->name,arcn->sb.st_uid,arcn->sb.st_gid) < 0) {
syswarn(1, oerrno, "Unable to create %s", arcn->name);
return(-1);
}
@@ -360,7 +360,7 @@ mk_link(to, to_sb, from, ign)
if (link(to, from) == 0)
break;
oerrno = errno;
- if (chk_path(from, to_sb->st_uid, to_sb->st_gid) == 0)
+ if (!nodirs && chk_path(from, to_sb->st_uid, to_sb->st_gid) == 0)
continue;
if (!ign) {
syswarn(1, oerrno, "Could not link to %s from %s", to,
@@ -468,7 +468,7 @@ node_creat(arcn)
if (++pass <= 1)
continue;
- if (chk_path(arcn->name,arcn->sb.st_uid,arcn->sb.st_gid) < 0) {
+ if (nodirs || chk_path(arcn->name,arcn->sb.st_uid,arcn->sb.st_gid) < 0) {
syswarn(1, oerrno, "Could not create: %s", arcn->name);
return(-1);
}
diff --git a/bin/pax/options.c b/bin/pax/options.c
index 513af6962e8..59f9059bd70 100644
--- a/bin/pax/options.c
+++ b/bin/pax/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.15 1997/02/27 23:32:58 michaels Exp $ */
+/* $OpenBSD: options.c,v 1.16 1997/03/02 09:46:47 tholo 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.15 1997/02/27 23:32:58 michaels Exp $";
+static char rcsid[] = "$OpenBSD: options.c,v 1.16 1997/03/02 09:46:47 tholo Exp $";
#endif
#endif /* not lint */
@@ -849,6 +849,39 @@ tar_options(argc, argv)
}
}
+int
+mkpath(path)
+ char *path;
+{
+ struct stat sb;
+ register char *slash;
+ int done = 0;
+
+ slash = path;
+
+ while (!done) {
+ slash += strspn(slash, "/");
+ slash += strcspn(slash, "/");
+
+ done = (*slash == '\0');
+ *slash = '\0';
+
+ if (stat(path, &sb)) {
+ if (errno != ENOENT || mkdir(path, 0777)) {
+ paxwarn(1, "%s", path);
+ return (-1);
+ }
+ } else if (!S_ISDIR(sb.st_mode)) {
+ syswarn(1, ENOTDIR, "%s", path);
+ return (-1);
+ }
+
+ if (!done)
+ *slash = '/';
+ }
+
+ return (0);
+}
/*
* cpio_options()
* look at the user specified flags. set globals as required and check if
@@ -874,9 +907,11 @@ cpio_options(argc, argv)
kflag = 1;
pids = 1;
pmode = 1;
+ pmtime = 0;
arcname = NULL;
dflag = 1;
act = -1;
+ nodirs = 1;
while ((c=getopt(argc,argv,"abcdfiklmoprstuvzABC:E:F:H:I:LO:SZ6")) != EOF)
switch (c) {
case 'a':
@@ -900,6 +935,7 @@ cpio_options(argc, argv)
/*
* create directories as needed
*/
+ nodirs = 0;
break;
case 'f':
/*
@@ -1081,12 +1117,15 @@ cpio_options(argc, argv)
cpio_usage();
break;
case COPY:
- if (optind >= argc) {
+ if (*argv == (char *)NULL) {
paxwarn(0, "Destination directory was not supplied");
cpio_usage();
}
+ dirptr = *argv;
+ if (mkpath(dirptr) < 0)
+ cpio_usage();
--argc;
- dirptr = argv[argc];
+ ++argv;
/* FALL THROUGH */
case ARCHIVE:
case APPND:
diff --git a/bin/pax/pax.c b/bin/pax/pax.c
index 2f0c5a6be8e..1fd965a1aff 100644
--- a/bin/pax/pax.c
+++ b/bin/pax/pax.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pax.c,v 1.5 1996/10/27 06:45:13 downsj Exp $ */
+/* $OpenBSD: pax.c,v 1.6 1997/03/02 09:46:49 tholo Exp $ */
/* $NetBSD: pax.c,v 1.5 1996/03/26 23:54:20 mrg Exp $ */
/*-
@@ -48,7 +48,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)pax.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: pax.c,v 1.5 1996/10/27 06:45:13 downsj Exp $";
+static char rcsid[] = "$OpenBSD: pax.c,v 1.6 1997/03/02 09:46:49 tholo Exp $";
#endif
#endif /* not lint */
@@ -94,6 +94,7 @@ int Zflag; /* same as uflg except after name mode */
int vfpart; /* is partial verbose output in progress */
int patime = 1; /* preserve file access time */
int pmtime = 1; /* preserve file modification times */
+int nodirs; /* do not create directories as needed */
int pmode; /* preserve file mode bits */
int pids; /* preserve file uid/gid */
int exit_val; /* exit value */