mirror of
https://github.com/coreutils/coreutils.git
synced 2024-11-23 18:05:42 +08:00
cksum: support transparent emulation of older utils
Support -b, --binary, and -t, --text to allow full emulation of older utilities with: exec cksum -a $algo --untagged "$@" Note this would diverge from OpenBSD's support of cksum -b. * src/digest.c: Change -b to mean --binary, not --base64 in all cases. Accept -b and -t in all cases. Keep --binary and --text undocumented for cksum. * tests/cksum/cksum-base64.pl: s/-b/--base64/. * tests/cksum/cksum-a.sh: Ensure cksum supports -b and -t appropriately. * NEWS: Mention the change in behavior.
This commit is contained in:
parent
2f1cffe07a
commit
5e1e0993b5
4
NEWS
4
NEWS
@ -47,6 +47,10 @@ GNU coreutils NEWS -*- outline -*-
|
|||||||
due to -i, or -u. Instead they only output this information with --debug.
|
due to -i, or -u. Instead they only output this information with --debug.
|
||||||
I.e., 'cp -u -v' etc. will have the same verbosity as before coreutils-9.3.
|
I.e., 'cp -u -v' etc. will have the same verbosity as before coreutils-9.3.
|
||||||
|
|
||||||
|
'cksum -b' no longer prints base64-encoded checksums. Rather that
|
||||||
|
short option is reserved to better support emulation of the standalone
|
||||||
|
checksum utilities with cksum.
|
||||||
|
|
||||||
** Improvements
|
** Improvements
|
||||||
|
|
||||||
cp, mv, and install now avoid copy_file_range on linux kernels before 5.3
|
cp, mv, and install now avoid copy_file_range on linux kernels before 5.3
|
||||||
|
28
src/digest.c
28
src/digest.c
@ -367,6 +367,7 @@ enum
|
|||||||
UNTAG_OPTION,
|
UNTAG_OPTION,
|
||||||
DEBUG_PROGRAM_OPTION,
|
DEBUG_PROGRAM_OPTION,
|
||||||
RAW_OPTION,
|
RAW_OPTION,
|
||||||
|
BASE64_OPTION,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct option const long_options[] =
|
static struct option const long_options[] =
|
||||||
@ -387,14 +388,13 @@ static struct option const long_options[] =
|
|||||||
|
|
||||||
# if HASH_ALGO_CKSUM
|
# if HASH_ALGO_CKSUM
|
||||||
{ "algorithm", required_argument, nullptr, 'a'},
|
{ "algorithm", required_argument, nullptr, 'a'},
|
||||||
{ "base64", no_argument, nullptr, 'b' },
|
{ "base64", no_argument, nullptr, BASE64_OPTION },
|
||||||
{ "debug", no_argument, nullptr, DEBUG_PROGRAM_OPTION},
|
{ "debug", no_argument, nullptr, DEBUG_PROGRAM_OPTION},
|
||||||
{ "raw", no_argument, nullptr, RAW_OPTION},
|
{ "raw", no_argument, nullptr, RAW_OPTION},
|
||||||
{ "untagged", no_argument, nullptr, UNTAG_OPTION },
|
{ "untagged", no_argument, nullptr, UNTAG_OPTION },
|
||||||
# else
|
# endif
|
||||||
{ "binary", no_argument, nullptr, 'b' },
|
{ "binary", no_argument, nullptr, 'b' },
|
||||||
{ "text", no_argument, nullptr, 't' },
|
{ "text", no_argument, nullptr, 't' },
|
||||||
# endif
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
{"sysv", no_argument, nullptr, 's'},
|
{"sysv", no_argument, nullptr, 's'},
|
||||||
@ -445,7 +445,7 @@ Print or check %s (%d-bit) checksums.\n\
|
|||||||
\n\
|
\n\
|
||||||
"), stdout);
|
"), stdout);
|
||||||
fputs (_("\
|
fputs (_("\
|
||||||
-b, --base64 emit base64-encoded digests, not hexadecimal\
|
--base64 emit base64-encoded digests, not hexadecimal\
|
||||||
\n\
|
\n\
|
||||||
"), stdout);
|
"), stdout);
|
||||||
#endif
|
#endif
|
||||||
@ -1074,14 +1074,7 @@ output_file (char const *file, int binary_file, void const *digest,
|
|||||||
if (!tagged)
|
if (!tagged)
|
||||||
{
|
{
|
||||||
putchar (' ');
|
putchar (' ');
|
||||||
|
|
||||||
# if HASH_ALGO_CKSUM
|
|
||||||
/* Simplify output as always in binary mode. */
|
|
||||||
putchar (' ');
|
|
||||||
# else
|
|
||||||
putchar (binary_file ? '*' : ' ');
|
putchar (binary_file ? '*' : ' ');
|
||||||
# endif
|
|
||||||
|
|
||||||
print_filename (file, needs_escape);
|
print_filename (file, needs_escape);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1344,11 +1337,10 @@ main (int argc, char **argv)
|
|||||||
bool do_check = false;
|
bool do_check = false;
|
||||||
int opt;
|
int opt;
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
int binary = -1;
|
||||||
#if HASH_ALGO_CKSUM
|
#if HASH_ALGO_CKSUM
|
||||||
int binary = 1;
|
|
||||||
bool prefix_tag = true;
|
bool prefix_tag = true;
|
||||||
#else
|
#else
|
||||||
int binary = -1;
|
|
||||||
bool prefix_tag = false;
|
bool prefix_tag = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1413,14 +1405,12 @@ main (int argc, char **argv)
|
|||||||
warn = false;
|
warn = false;
|
||||||
quiet = false;
|
quiet = false;
|
||||||
break;
|
break;
|
||||||
# if !HASH_ALGO_CKSUM
|
|
||||||
case 'b':
|
case 'b':
|
||||||
binary = 1;
|
binary = 1;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
binary = 0;
|
binary = 0;
|
||||||
break;
|
break;
|
||||||
# endif
|
|
||||||
case 'w':
|
case 'w':
|
||||||
status_only = false;
|
status_only = false;
|
||||||
warn = true;
|
warn = true;
|
||||||
@ -1438,7 +1428,7 @@ main (int argc, char **argv)
|
|||||||
strict = true;
|
strict = true;
|
||||||
break;
|
break;
|
||||||
# if HASH_ALGO_CKSUM
|
# if HASH_ALGO_CKSUM
|
||||||
case 'b':
|
case BASE64_OPTION:
|
||||||
base64_digest = true;
|
base64_digest = true;
|
||||||
break;
|
break;
|
||||||
case RAW_OPTION:
|
case RAW_OPTION:
|
||||||
@ -1527,7 +1517,11 @@ main (int argc, char **argv)
|
|||||||
However that's invasive enough that it was agreed to
|
However that's invasive enough that it was agreed to
|
||||||
not support this mode with --tag, as --text use cases
|
not support this mode with --tag, as --text use cases
|
||||||
are adequately supported by the default output format. */
|
are adequately supported by the default output format. */
|
||||||
|
#if !HASH_ALGO_CKSUM
|
||||||
error (0, 0, _("--tag does not support --text mode"));
|
error (0, 0, _("--tag does not support --text mode"));
|
||||||
|
#else
|
||||||
|
error (0, 0, _("--text mode is only supported with --untagged"));
|
||||||
|
#endif
|
||||||
usage (EXIT_FAILURE);
|
usage (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1546,14 +1540,12 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !HASH_ALGO_CKSUM
|
|
||||||
if (0 <= binary && do_check)
|
if (0 <= binary && do_check)
|
||||||
{
|
{
|
||||||
error (0, 0, _("the --binary and --text options are meaningless when "
|
error (0, 0, _("the --binary and --text options are meaningless when "
|
||||||
"verifying checksums"));
|
"verifying checksums"));
|
||||||
usage (EXIT_FAILURE);
|
usage (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ignore_missing && !do_check)
|
if (ignore_missing && !do_check)
|
||||||
{
|
{
|
||||||
|
@ -23,27 +23,32 @@ cat > input_options <<\EOF || framework_failure_
|
|||||||
bsd sum -r
|
bsd sum -r
|
||||||
sysv sum -s
|
sysv sum -s
|
||||||
crc cksum
|
crc cksum
|
||||||
md5 md5sum -t
|
md5 md5sum MODE
|
||||||
sha1 sha1sum -t
|
sha1 sha1sum MODE
|
||||||
sha224 sha224sum -t
|
sha224 sha224sum MODE
|
||||||
sha256 sha256sum -t
|
sha256 sha256sum MODE
|
||||||
sha384 sha384sum -t
|
sha384 sha384sum MODE
|
||||||
sha512 sha512sum -t
|
sha512 sha512sum MODE
|
||||||
blake2b b2sum -t
|
blake2b b2sum MODE
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
while read algo prog; do
|
while read algo prog mode; do
|
||||||
$prog /dev/null >> out || continue
|
for cmode in '-b' '-t'; do
|
||||||
cksum --untagged --algorithm=$algo /dev/null > out-c || fail=1
|
pmode="$mode"
|
||||||
|
case $pmode in MODE) pmode=$cmode;; esac
|
||||||
|
|
||||||
case "$algo" in
|
$prog $pmode /dev/null >> out || continue
|
||||||
bsd) ;;
|
cksum --untagged $cmode --algorithm=$algo /dev/null > out-c || fail=1
|
||||||
sysv) ;;
|
|
||||||
crc) ;;
|
|
||||||
*) cksum --check --algorithm=$algo out-c || fail=1 ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
cat out-c >> out-a || framework_failure_
|
case "$algo" in
|
||||||
|
bsd) ;;
|
||||||
|
sysv) ;;
|
||||||
|
crc) ;;
|
||||||
|
*) cksum --check --algorithm=$algo out-c || fail=1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
cat out-c >> out-a || framework_failure_
|
||||||
|
done
|
||||||
done < input_options
|
done < input_options
|
||||||
compare out out-a || fail=1
|
compare out out-a || fail=1
|
||||||
|
|
||||||
|
@ -51,9 +51,9 @@ sub fmt ($$) {
|
|||||||
|
|
||||||
my @Tests =
|
my @Tests =
|
||||||
(
|
(
|
||||||
# Ensure that each of the above works with -b:
|
# Ensure that each of the above works with --base64:
|
||||||
(map {my ($h,$v)= @$_; my $o=fmt $h,$v;
|
(map {my ($h,$v)= @$_; my $o=fmt $h,$v;
|
||||||
[$h, "-ba $h", {IN=>{f=>''}}, {OUT=>"$o\n"}]} @pairs),
|
[$h, "--base64 -a $h", {IN=>{f=>''}}, {OUT=>"$o\n"}]} @pairs),
|
||||||
|
|
||||||
# For each that accepts --check, ensure that works with base64 digests:
|
# For each that accepts --check, ensure that works with base64 digests:
|
||||||
(map {my ($h,$v)= @$_; my $o=fmt $h,$v;
|
(map {my ($h,$v)= @$_; my $o=fmt $h,$v;
|
||||||
|
Loading…
Reference in New Issue
Block a user