ar: add -U (unique) option to disable -D (deterministic) mode

This is required in order for us to support deterministic mode by
default.  If multiple -D or -U options are specified on the command
line, the final one takes precedence.  GNU ar also uses -U for this.

An equivalent change will be applied to ELF Tool Chain's version of ar.

PR:		196929
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D3175
This commit is contained in:
emaste 2015-07-24 17:46:43 +00:00
parent 80a6ca2f84
commit c58042ff07
2 changed files with 34 additions and 7 deletions

View File

@ -23,7 +23,7 @@
.\" .\"
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd December 22, 2011 .Dd July 24, 2015
.Dt AR 1 .Dt AR 1
.Os .Os
.Sh NAME .Sh NAME
@ -66,6 +66,7 @@
.Op Fl D .Op Fl D
.Op Fl f .Op Fl f
.Op Fl s | Fl S .Op Fl s | Fl S
.Op Fl U
.Op Fl v .Op Fl v
.Op Fl z .Op Fl z
.Ar archive .Ar archive
@ -82,6 +83,7 @@
.Op Fl j .Op Fl j
.Op Fl s | Fl S .Op Fl s | Fl S
.Op Fl u .Op Fl u
.Op Fl U
.Op Fl v .Op Fl v
.Op Fl z .Op Fl z
.Ar archive .Ar archive
@ -112,6 +114,7 @@
.Fl M .Fl M
.Nm ranlib .Nm ranlib
.Op Fl D .Op Fl D
.Op Fl U
.Ar archive ... .Ar archive ...
.Sh DESCRIPTION .Sh DESCRIPTION
The The
@ -207,6 +210,11 @@ and 0644 instead of file mode from the members named by arguments
.Ar . .Ar .
This ensures that checksums on the resulting archives are reproducible This ensures that checksums on the resulting archives are reproducible
when member contents are identical. when member contents are identical.
If multiple
.Fl D
and
.Fl U
options are specified on the command line, the final one takes precedence.
.It Fl f .It Fl f
Synonymous with option Synonymous with option
.Fl T . .Fl T .
@ -316,6 +324,19 @@ option, the members specified by arguments
.Ar .Ar
will be extracted only if they are newer than the corresponding will be extracted only if they are newer than the corresponding
files in the file system. files in the file system.
.It Fl U
When used in combination with the
.Fl r
or
.Fl q
option, insert the real mtime, uid and gid, and file mode values
from the members named by arguments
.Ar .
If multiple
.Fl D
and
.Fl U
options are specified on the command line, the final one takes precedence.
.It Fl v .It Fl v
Provide verbose output. Provide verbose output.
When used with the When used with the

View File

@ -113,7 +113,7 @@ main(int argc, char **argv)
len = strlen(bsdar->progname); len = strlen(bsdar->progname);
if (len >= strlen("ranlib") && if (len >= strlen("ranlib") &&
strcmp(bsdar->progname + len - strlen("ranlib"), "ranlib") == 0) { strcmp(bsdar->progname + len - strlen("ranlib"), "ranlib") == 0) {
while ((opt = getopt_long(argc, argv, "tDV", longopts, while ((opt = getopt_long(argc, argv, "tDUV", longopts,
NULL)) != -1) { NULL)) != -1) {
switch(opt) { switch(opt) {
case 't': case 't':
@ -122,6 +122,9 @@ main(int argc, char **argv)
case 'D': case 'D':
bsdar->options |= AR_D; bsdar->options |= AR_D;
break; break;
case 'U':
bsdar->options &= ~AR_D;
break;
case 'V': case 'V':
ranlib_version(); ranlib_version();
break; break;
@ -157,7 +160,7 @@ main(int argc, char **argv)
} }
} }
while ((opt = getopt_long(argc, argv, "abCcdDfijlMmopqrSsTtuVvxz", while ((opt = getopt_long(argc, argv, "abCcdDfijlMmopqrSsTtUuVvxz",
longopts, NULL)) != -1) { longopts, NULL)) != -1) {
switch(opt) { switch(opt) {
case 'a': case 'a':
@ -216,6 +219,9 @@ main(int argc, char **argv)
case 't': case 't':
set_mode(bsdar, opt); set_mode(bsdar, opt);
break; break;
case 'U':
bsdar->options &= ~AR_D;
break;
case 'u': case 'u':
bsdar->options |= AR_U; bsdar->options |= AR_U;
break; break;
@ -364,9 +370,9 @@ bsdar_usage(void)
(void)fprintf(stderr, "\tar -m [-Tjsvz] archive file ...\n"); (void)fprintf(stderr, "\tar -m [-Tjsvz] archive file ...\n");
(void)fprintf(stderr, "\tar -m [-Tabijsvz] position archive file ...\n"); (void)fprintf(stderr, "\tar -m [-Tabijsvz] position archive file ...\n");
(void)fprintf(stderr, "\tar -p [-Tv] archive [file ...]\n"); (void)fprintf(stderr, "\tar -p [-Tv] archive [file ...]\n");
(void)fprintf(stderr, "\tar -q [-TcDjsvz] archive file ...\n"); (void)fprintf(stderr, "\tar -q [-TcDjsUvz] archive file ...\n");
(void)fprintf(stderr, "\tar -r [-TcDjsuvz] archive file ...\n"); (void)fprintf(stderr, "\tar -r [-TcDjsUuvz] archive file ...\n");
(void)fprintf(stderr, "\tar -r [-TabcDijsuvz] position archive file ...\n"); (void)fprintf(stderr, "\tar -r [-TabcDijsUuvz] position archive file ...\n");
(void)fprintf(stderr, "\tar -s [-jz] archive\n"); (void)fprintf(stderr, "\tar -s [-jz] archive\n");
(void)fprintf(stderr, "\tar -t [-Tv] archive [file ...]\n"); (void)fprintf(stderr, "\tar -t [-Tv] archive [file ...]\n");
(void)fprintf(stderr, "\tar -x [-CTouv] archive [file ...]\n"); (void)fprintf(stderr, "\tar -x [-CTouv] archive [file ...]\n");
@ -378,7 +384,7 @@ static void
ranlib_usage(void) ranlib_usage(void)
{ {
(void)fprintf(stderr, "usage: ranlib [-t] archive ...\n"); (void)fprintf(stderr, "usage: ranlib [-DtU] archive ...\n");
(void)fprintf(stderr, "\tranlib -V\n"); (void)fprintf(stderr, "\tranlib -V\n");
exit(EX_USAGE); exit(EX_USAGE);
} }