add -p flag, similar to cp(1)

This commit is contained in:
christos 1998-09-28 08:16:15 +00:00
parent ddb60058ff
commit 710d4c153b
2 changed files with 39 additions and 22 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: install.1,v 1.10 1997/10/20 03:32:25 lukem Exp $ .\" $NetBSD: install.1,v 1.11 1998/09/28 08:16:15 christos Exp $
.\" .\"
.\" Copyright (c) 1987, 1990, 1993 .\" Copyright (c) 1987, 1990, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -41,7 +41,7 @@
.Nd install binaries .Nd install binaries
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl cs .Op Fl cps
.Op Fl f Ar flags .Op Fl f Ar flags
.Op Fl g Ar group .Op Fl g Ar group
.Op Fl l Ar linkflags .Op Fl l Ar linkflags
@ -49,7 +49,7 @@
.Op Fl o Ar owner .Op Fl o Ar owner
.Ar file1 file2 .Ar file1 file2
.Nm "" .Nm ""
.Op Fl cs .Op Fl cps
.Op Fl f Ar flags .Op Fl f Ar flags
.Op Fl g Ar group .Op Fl g Ar group
.Op Fl l Ar linkflags .Op Fl l Ar linkflags
@ -59,7 +59,7 @@
\&... \&...
.Ar fileN directory .Ar fileN directory
.Nm "" .Nm ""
.Fl d .Fl pd
.Op Fl m Ar mode .Op Fl m Ar mode
.Op Fl o Ar owner .Op Fl o Ar owner
.Op Fl g Ar group .Op Fl g Ar group
@ -118,6 +118,8 @@ are:
are hard links for files on the same filesystem, symbolic otherwise. are hard links for files on the same filesystem, symbolic otherwise.
.It Fl o .It Fl o
Specify an owner. Specify an owner.
.It Fl p
Preserve the source files access and modification times.
.It Fl s .It Fl s
.Nm .Nm
exec's the command exec's the command

View File

@ -1,4 +1,4 @@
/* $NetBSD: xinstall.c,v 1.25 1998/02/20 09:27:21 mycroft Exp $ */ /* $NetBSD: xinstall.c,v 1.26 1998/09/28 08:16:15 christos Exp $ */
/* /*
* Copyright (c) 1987, 1993 * Copyright (c) 1987, 1993
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\
#if 0 #if 0
static char sccsid[] = "@(#)xinstall.c 8.1 (Berkeley) 7/21/93"; static char sccsid[] = "@(#)xinstall.c 8.1 (Berkeley) 7/21/93";
#else #else
__RCSID("$NetBSD: xinstall.c,v 1.25 1998/02/20 09:27:21 mycroft Exp $"); __RCSID("$NetBSD: xinstall.c,v 1.26 1998/09/28 08:16:15 christos Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -68,7 +68,7 @@ __RCSID("$NetBSD: xinstall.c,v 1.25 1998/02/20 09:27:21 mycroft Exp $");
struct passwd *pp; struct passwd *pp;
struct group *gp; struct group *gp;
int docopy, dodir, dostrip, dolink; int docopy, dodir, dostrip, dolink, dopreserve;
int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
char pathbuf[MAXPATHLEN]; char pathbuf[MAXPATHLEN];
uid_t uid; uid_t uid;
@ -106,11 +106,14 @@ main(argc, argv)
char *flags = NULL, *to_name, *group = NULL, *owner = NULL; char *flags = NULL, *to_name, *group = NULL, *owner = NULL;
iflags = 0; iflags = 0;
while ((ch = getopt(argc, argv, "cf:g:l:m:o:sd")) != -1) while ((ch = getopt(argc, argv, "cdf:g:l:m:o:ps")) != -1)
switch((char)ch) { switch((char)ch) {
case 'c': case 'c':
docopy = 1; docopy = 1;
break; break;
case 'd':
dodir = 1;
break;
case 'f': case 'f':
flags = optarg; flags = optarg;
if (string_to_flags(&flags, &fset, NULL)) if (string_to_flags(&flags, &fset, NULL))
@ -120,20 +123,6 @@ main(argc, argv)
case 'g': case 'g':
group = optarg; group = optarg;
break; break;
case 'm':
if (!(set = setmode(optarg)))
errx(1, "%s: invalid file mode", optarg);
mode = getmode(set, 0);
break;
case 'o':
owner = optarg;
break;
case 's':
dostrip = 1;
break;
case 'd':
dodir = 1;
break;
case 'l': case 'l':
for (p = optarg; *p; p++) for (p = optarg; *p; p++)
switch (*p) { switch (*p) {
@ -162,6 +151,20 @@ main(argc, argv)
break; break;
} }
break; break;
case 'm':
if (!(set = setmode(optarg)))
errx(1, "%s: invalid file mode", optarg);
mode = getmode(set, 0);
break;
case 'o':
owner = optarg;
break;
case 'p':
dopreserve = 1;
break;
case 's':
dostrip = 1;
break;
case '?': case '?':
default: default:
usage(); usage();
@ -395,6 +398,18 @@ install(from_name, to_name, fset, flags)
warn("%s: chflags", to_name); warn("%s: chflags", to_name);
} }
/*
* Preserve the date of the source file.
*/
if (dopreserve) {
struct timeval tv[2];
TIMESPEC_TO_TIMEVAL(&tv[0], &from_sb.st_atimespec);
TIMESPEC_TO_TIMEVAL(&tv[1], &from_sb.st_mtimespec);
if (futimes(to_fd, tv) == -1)
warn("%s: futimes", to_name);
}
(void)close(to_fd); (void)close(to_fd);
if (!docopy && !devnull && unlink(from_name)) if (!docopy && !devnull && unlink(from_name))
err(1, "%s", from_name); err(1, "%s", from_name);