Date: Tue, 29 Jun 2021 07:22:39 GMT From: =?utf-8?Q?Stefan E=C3=9Fer?= <se@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: b33d1898c1b0 - main - md5: Improve compatibility with coreutils and format fix Message-ID: <202106290722.15T7Mdev067861@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=b33d1898c1b0e6d76b52eb48078260588802dc95 commit b33d1898c1b0e6d76b52eb48078260588802dc95 Author: Stefan Eßer <se@FreeBSD.org> AuthorDate: 2021-06-29 07:01:13 +0000 Commit: Stefan Eßer <se@FreeBSD.org> CommitDate: 2021-06-29 07:21:57 +0000 md5: Improve compatibility with coreutils and format fix The previous changes that added support for the coreutils -c option modified the output generated by passing -r to match that of the coreutils versions. The difference is that coreutils separates the hash from the file name by two blanks " " (or a blank followed by an asterisk " *" with the -b option denoting). While most scripts or users will not notice the difference, it might be considered a violation of POLA and this commit reverts the change for the non-sum programs. These will print a single blank " " as the separator, as they die before the previous commit. In order to still generate output that is identical to that of the coreutils programs, this commit generates the " " or " *" separator used by them for the -sum versions, depending on the presence of the -b option. MFC after: 3 days --- sbin/md5/md5.1 | 25 ++++++++++++++++--------- sbin/md5/md5.c | 10 +++++++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/sbin/md5/md5.1 b/sbin/md5/md5.1 index da034d1298c5..2b1da85c080f 100644 --- a/sbin/md5/md5.1 +++ b/sbin/md5/md5.1 @@ -1,5 +1,5 @@ .\" $FreeBSD$ -.Dd June 24, 2021 +.Dd June 29, 2021 .Dt MD5 1 .Os .Sh NAME @@ -77,9 +77,11 @@ The hexadecimal checksum of each file listed on the command line is printed after the options are processed. .Bl -tag -width indent .It Fl b -Ignored for compatibility with the coreutils +Make the .Nm -sum -programs. +programs separate hash and digest with a blank followed by an asterisk instead +of by 2 blank characters for full compatibility with the output generated by the +coreutils versions of these programs. .It Fl c Ar string If the program was called with a name that does not end in .Nm sum , @@ -88,13 +90,13 @@ compare the digest of the file against this string. .It Fl c Ar file If the program was called with a name that does end in .Nm sum , -the file passed as argument must contain digest lines generated by the same digest algorithm -with or without the +the file passed as argument must contain digest lines generated by the same +digest algorithm with or without the .Fl r option .Pq i.e. in either classical BSD format or in GNU coreutils format . -A line with file name followed by -.Dq : +A line with the file name followed by a colon +.Dq ":" and either OK or FAILED is written for each well-formed line in the digest file. If applicable, the number of failed comparisons and the number of lines that were skipped since they were not well-formed are printed at the end. @@ -157,8 +159,13 @@ $ echo -n Hello | md5 Calculate the checksum of multiple files reversing the output: .Bd -literal -offset indent $ md5 -r /boot/loader.conf /etc/rc.conf -ada5f60f23af88ff95b8091d6d67bef6 /boot/loader.conf -d80bf36c332dc0fdc479366ec3fa44cd /etc/rc.conf +ada5f60f23af88ff95b8091d6d67bef6 /boot/loader.conf +d80bf36c332dc0fdc479366ec3fa44cd /etc/rc.conf +.Pd +The +.Nm -sum +variants put 2 blank characters between hash and file name for full compatibilty +with the coreutils versions of these commands. .Ed .Pp Write the digest for diff --git a/sbin/md5/md5.c b/sbin/md5/md5.c index 43a76227a9d2..7235e6e0a39f 100644 --- a/sbin/md5/md5.c +++ b/sbin/md5/md5.c @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #define TEST_BLOCK_COUNT 100000 #define MDTESTCOUNT 8 +static int bflag; static int cflag; static int pflag; static int qflag; @@ -301,6 +302,7 @@ main(int argc, char *argv[]) while ((ch = getopt(argc, argv, "bc:pqrs:tx")) != -1) switch (ch) { case 'b': + bflag = 1; break; case 'c': cflag = 1; @@ -436,7 +438,13 @@ MDOutput(const Algorithm_t *alg, char *p, char *argv[]) printf("%s\n", p); } else { if (rflag) - printf("%s %s", p, *argv); + if (gnu_emu) + if (bflag) + printf("%s *%s", p, *argv); + else + printf("%s %s", p, *argv); + else + printf("%s %s", p, *argv); else printf("%s (%s) = %s", alg->name, *argv, p); if (checkAgainst) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106290722.15T7Mdev067861>