commit: 362c7e27f8c4d599f6c4156c074dec7345b7c5df
parent 776a50280df49df3e5a8c681678ccdf079665f22
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 6 Mar 2025 06:02:28 +0100
cmd/chmod: drop -F alias for --reference
At this point in utils-std I'd rather avoid the possibility
of creating future conflicts with other utilities.
Diffstat:
3 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/cmd/chmod.1 b/cmd/chmod.1
@@ -14,7 +14,7 @@
.Ar file...
.Nm
.Op Fl cRv
-.Fl F Ar ref_file
+.Fl -reference Ar ref_file
.Ar file...
.Sh DESCRIPTION
.Nm
@@ -46,7 +46,7 @@ like so:
.Bl -tag -width Ds
.It Fl c
Print mode changes
-.It Fl F Ar ref_file
+.It Fl -reference Ar ref_file
Copy permission bits from
.Ar ref_file
into each
@@ -160,16 +160,10 @@ IEEE Std 1003.1-2024 (“POSIX.1”)
specification.
.Pp
The
-.Fl c
-and
+.Fl c ,
.Fl v
-options are present for compatibility with other modern systems such as BusyBox and GNU coreutils.
-Similarly the
-.Fl F
-option was created for compatibility with
+and
.Fl -reference
-from GNU, BusyBox and
-.Nx
-while keeping the possibility of using short options.
+options are present for compatibility with other modern systems such as BusyBox and GNU coreutils.
.Sh AUTHORS
.An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me
diff --git a/cmd/chmod.c b/cmd/chmod.c
@@ -325,12 +325,14 @@ main(int argc, char *argv[])
char *ref_file = NULL;
#ifdef HAS_GETOPT_LONG
- // Strictly for GNUisms compatibility so no long-only options
// clang-format off
+ enum long_opt_vals {
+ OPT_REFERENCE = 1,
+ };
static struct option opts[] = {
{"changes", no_argument, 0, 'c'},
{"recursive", no_argument, 0, 'R'},
- {"reference", required_argument, 0, 'F'},
+ {"reference", required_argument, 0, OPT_REFERENCE},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0},
};
@@ -352,9 +354,9 @@ main(int argc, char *argv[])
#ifdef HAS_GETOPT_LONG
// Need + as first character to get POSIX-style option parsing
- c = getopt_long(argc, argv, "+:cF:Rv", opts, NULL);
+ c = getopt_long(argc, argv, "+:cRv", opts, NULL);
#else
- c = getopt(argc, argv, ":cF:Rv");
+ c = getopt(argc, argv, ":cRv");
#endif
if(c == -1) break;
@@ -363,7 +365,7 @@ main(int argc, char *argv[])
case 'c': // GNU
opt_c = true;
break;
- case 'F': // GNU & NetBSD for --reference, utils-std for -F
+ case OPT_REFERENCE: // GNU & NetBSD
ref_file = optarg;
break;
case 'R': // POSIX
diff --git a/test-cmd/chmod.sh b/test-cmd/chmod.sh
@@ -2,9 +2,10 @@
# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
# SPDX-License-Identifier: MPL-2.0
-target="$(dirname "$0")/../cmd/chmod"
+WD="$(dirname "$0")/../"
+target="${WD}/cmd/chmod"
plans=13
-. "$(dirname "$0")/tap.sh"
+. "${WD}/test-cmd/tap.sh"
tmpfile="${TMPDIR-/tmp}/test_chmod_$(date +%s)"
ref_file="${TMPDIR-/tmp}/test_chmod_$(date +%s).ref"
@@ -44,9 +45,14 @@ t '__mode:-x,+w' "-v -- -x,+w $tmpfile" "chmod: Permissions changed from 00133/-
t '__mode:-w' "-v -- -w $tmpfile" "chmod: Permissions changed from 00222/--w--w--w- to 00022/-----w--w- for '${tmpfile}'
"
-t 'ref_file' "-v -F $ref_file $tmpfile" "chmod: Permissions changed from 00022/-----w--w- to 00644/-rw-r--r-- for '${tmpfile}'
+if grep -q HAS_GETOPT_LONG "${WD}/config.h"; then
+ t ref_file "-v --reference $ref_file $tmpfile" "chmod: Permissions changed from 00022/-----w--w- to 00644/-rw-r--r-- for '${tmpfile}'
"
-t 'ref_file:repeat' "-v -F $ref_file $tmpfile" "chmod: Permissions already set to 00644/-rw-r--r-- for '${tmpfile}'
+ t ref_file:repeat "-v --reference $ref_file $tmpfile" "chmod: Permissions already set to 00644/-rw-r--r-- for '${tmpfile}'
"
+else
+ skip ref_file 'Lacks getopt_long'
+ skip ref_file:repeat 'Lacks getopt_long'
+fi
-rm -f "$tmpfile" || exit 1
+rm -f "$tmpfile" "$ref_file" || exit 1