.\" (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
.Xr pax 1 ,
.Xr tar 1
.Sh BUGS
-The
-.Fl d
-option is the default and cannot be turned off.
The
.Fl s
and
-/* $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 $ */
/*-
extern int vfpart;
extern int patime;
extern int pmtime;
+extern int nodirs;
extern int pmode;
extern int pids;
extern int exit_val;
-/* $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 $ */
/*-
#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 */
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);
}
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,
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);
}
-/* $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 $ */
/*-
#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 */
}
}
+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
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':
/*
* create directories as needed
*/
+ nodirs = 0;
break;
case 'f':
/*
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:
-/* $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 $ */
/*-
#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 */
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 */