On 17/09/2021 19:25, Pádraig Brady wrote:
On 17/09/2021 18:43, Eric Blake wrote:
[IOn Wed, Sep 15, 2021 at 01:40:33PM +0100, Pádraig Brady wrote:
This format is a better default, since it results in simpler usage,
as you don't need to specify --tag on generation or -a on
checking invocations.  Also it's a more general format supporting
mixed and length adjusted digests.


@@ -4143,6 +4153,8 @@ indicating there was a failure.
   @item --tag
   @opindex --tag
   @cindex BSD output
+Note this option is not supported by the @command{cksum} command,
+as this is the default output format that it uses.

Shouldn't we still support the option, even if it is a no-op in the
common case, so that someone can do actions similar to:

alias mysum='cksum --untagged '

and then invoke 'mysum --tag' to turn it back on?

Maybe.
Perhaps on some systems only cksum might be installed,
with md5sum etc. being provided as simple wrappers like:

    exec cksum -a md5 --untagged "$@"

Though that begs the question, should cksum support all of
--tag, --text, --binary ?

I'd be 60:40 for adding the --tag option to cksum,

I'll pushed the attached later to support cksum --tag
for the reasons above.

cheers,
Pádraig
>From 079cb6f87ee80a90b1723f662d41da426017a983 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Mon, 20 Sep 2021 11:54:08 +0100
Subject: [PATCH] cksum: support more transparent emulation of older utils

* src/digest.c: Allow using the --untagged option with --check,
so that `cksum -a md5 --untagged` used to emulate md5sum for example,
may be augmented with the --check option.  Also support the --tag
option with cksum, to allow overriding a previous --untagged setting.
* doc/coreutils.texi: Adjust accordingly.
* tests/misc/cksum-a.sh: Likewise.
---
 doc/coreutils.texi    |  8 ++++----
 src/digest.c          | 17 ++++++-----------
 tests/misc/cksum-a.sh |  1 -
 3 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 05c5d2e5d..d962d363e 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -3934,8 +3934,9 @@ for each given @var{file}, or standard input if none are given or for a
 @var{file} of @samp{-}.
 
 cksum also supports the @option{-a,--algorithm} option to select the
-digest algorithm to use, and this is the preferred interface
-to these digests, subsuming the other standalone checksumming utilities.
+digest algorithm to use. @command{cksum} is the preferred interface
+to these digests, subsuming the other standalone checksumming utilities,
+which can be emulated using @code{cksum -a md5 --untagged "$@@"} etc.
 Synopsis:
 
 @example
@@ -4162,8 +4163,6 @@ indicating there was a failure.
 @item --tag
 @opindex --tag
 @cindex BSD output
-Note this option is not supported by the @command{cksum} command,
-as this is the default output format that it uses.
 Output BSD style checksums, which indicate the checksum algorithm used.
 As a GNU extension, if @option{--zero} is not used, file names with problematic
 characters are escaped as described above, with the same escaping indicator of
@@ -4171,6 +4170,7 @@ characters are escaped as described above, with the same escaping indicator of
 The @option{--tag} option implies binary mode, and is disallowed with
 @option{--text} mode as supporting that would unnecessarily complicate
 the output format, while providing little benefit.
+The @command{cksum} command, uses @option{--tag} as its default output format.
 
 @item -t
 @itemx --text
diff --git a/src/digest.c b/src/digest.c
index 9398a133e..de2decc19 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -372,6 +372,7 @@ static struct option const long_options[] =
   { "status", no_argument, NULL, STATUS_OPTION },
   { "warn", no_argument, NULL, 'w' },
   { "strict", no_argument, NULL, STRICT_OPTION },
+  { "tag", no_argument, NULL, TAG_OPTION },
   { "zero", no_argument, NULL, 'z' },
 
 # if HASH_ALGO_CKSUM
@@ -381,7 +382,6 @@ static struct option const long_options[] =
 # else
   { "binary", no_argument, NULL, 'b' },
   { "text", no_argument, NULL, 't' },
-  { "tag", no_argument, NULL, TAG_OPTION },
 # endif
 
 #else
@@ -452,6 +452,9 @@ Print or check %s (%d-bit) checksums.\n\
 "), stdout);
 # endif
 # if HASH_ALGO_CKSUM
+      fputs (_("\
+      --tag            create a BSD-style checksum (the default)\n\
+"), stdout);
       fputs (_("\
       --untagged       create a reversed style checksum, without digest type\n\
 "), stdout);
@@ -1335,12 +1338,11 @@ main (int argc, char **argv)
       case UNTAG_OPTION:
         prefix_tag = false;
         break;
-# else
+# endif
       case TAG_OPTION:
         prefix_tag = true;
         binary = 1;
         break;
-# endif
       case 'z':
         digest_delim = '\0';
         break;
@@ -1421,14 +1423,7 @@ main (int argc, char **argv)
                      "verifying checksums"));
       usage (EXIT_FAILURE);
     }
-#if HASH_ALGO_CKSUM
-  if (!prefix_tag && do_check)
-    {
-      error (0, 0, _("the --untagged option is meaningless when "
-                     "verifying checksums"));
-      usage (EXIT_FAILURE);
-    }
-#else
+#if !HASH_ALGO_CKSUM
   if (prefix_tag && do_check)
     {
       error (0, 0, _("the --tag option is meaningless when "
diff --git a/tests/misc/cksum-a.sh b/tests/misc/cksum-a.sh
index 9a58e1c2d..83dde1ff3 100755
--- a/tests/misc/cksum-a.sh
+++ b/tests/misc/cksum-a.sh
@@ -47,7 +47,6 @@ while read algo prog; do
 done < input_options
 compare out out-a || fail=1
 
-returns_ 1 cksum -a bsd --tag </dev/null || fail=1
 returns_ 1 cksum -a bsd --check </dev/null || fail=1
 
 Exit $fail
-- 
2.26.2

Reply via email to