[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: readlink(1) of more than one file?
From: |
Pádraig Brady |
Subject: |
Re: readlink(1) of more than one file? |
Date: |
Mon, 17 Dec 2012 13:21:38 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 |
On 12/16/2012 12:29 AM, Pádraig Brady wrote:
On 12/15/2012 11:10 PM, Dmitry V. Levin wrote:
On Sat, Dec 15, 2012 at 03:40:36PM +0000, Pádraig Brady wrote:
On 12/15/2012 03:09 PM, Bernhard Voelker wrote:
[...]
And finally: -n is pretty much useless now with multiple arguments,
because the output is just concatenated together:
$ src/readlink --no /user /user
homehome
Wouldn't it be better to allow -n only for single-argument calls,
or use a blank " " as delimiter between the output for multiple
args, or warn?
Since -n is a largely redundant option anyway,
I was just keeping it around for compat reasons.
BSD operates like above, so why diverge?
If BSD readlink -n does something totally useless, it's not a reason
to follow and introduce that useless behaviour in GNU readlink.
I've tried to construct an example where readlink -n with multiple
arguments could be used harmlessly, and the only case I have so far
is when readlink's output does not matter (e.g. grep -q ^.) or discarded
completely.
So, please do not add multiple arguments support to readlink -n unless
you can also add a usage example for that feature.
Ok fair enough.
I'll adjust to that -n suppresses only the trailing delimiter.
Pushing with this adjustment.
thanks,
Pádraig.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index d393063..0646f82 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -9789,7 +9789,8 @@ as a directory.
@itemx --no-newline
@opindex -n
@opindex --no-newline
-Do not print the output delimiter.
+Do not print the output delimiter, when a single @var{file} is specified.
+Print a warning if specified along with multiple @var{file}s.
@item -s
@itemx -q
diff --git a/src/readlink.c b/src/readlink.c
index de8211f..ff7d67f 100644
--- a/src/readlink.c
+++ b/src/readlink.c
@@ -77,7 +77,7 @@ usage (int status)
every component of the given name recursively,\
\n\
without requirements on components existence\n\
- -n, --no-newline do not output a delimiter after each item\n\
+ -n, --no-newline do not output the trailing delimiter\n\
-q, --quiet,\n\
-s, --silent suppress most error messages\n\
-v, --verbose report error messages\n\
@@ -146,6 +146,13 @@ main (int argc, char **argv)
usage (EXIT_FAILURE);
}
+ if (argc - optind > 1)
+ {
+ if (no_newline)
+ error (0, 0, _("ignoring --no-newline with multiple arguments"));
+ no_newline = false;
+ }
+
for (; optind < argc; ++optind)
{
const char *fname = argv[optind];
diff --git a/tests/readlink/multi.sh b/tests/readlink/multi.sh
index 9f22791..9a853e1 100755
--- a/tests/readlink/multi.sh
+++ b/tests/readlink/multi.sh
@@ -27,16 +27,20 @@ readlink link1 link2 && fail=1
readlink link1 link2 link1 && fail=1
readlink -m link1 link2 || fail=1
-printf "/1\0/1\0" > exp || framework_failure_
+printf '/1\0/1\0' > exp || framework_failure_
readlink -m --zero /1 /1 > out || fail=1
compare exp out || fail=1
-# The largely redundant --no-newline option
-# is kept around for mainly compatibility reasons,
-# so we behave like BSD here and don't output
-# delimiters, even if handling multiple arguments.
-printf "/1/1" > exp || framework_failure_
+# The largely redundant --no-newline option is ignored with multiple args.
+# Note BSD's readlink suppresses all delimiters, even with multiple args,
+# but that functionality was not thought useful.
readlink -n -m --zero /1 /1 > out || fail=1
compare exp out || fail=1
+# Noting the edge case that the last xargs run may not have a delimiter
+rm out || framework_failure_
+printf '/1\0/1\0/1' > exp || framework_failure_
+printf '/1 /1 /1' | xargs -n2 readlink -n -m --zero >> out || fail=1
+compare exp out || fail=1
+
Exit $fail
- Re: readlink(1) of more than one file?, (continued)
- Re: readlink(1) of more than one file?, Pádraig Brady, 2012/12/12
- Re: readlink(1) of more than one file?, Jim Meyering, 2012/12/12
- Re: readlink(1) of more than one file?, Jim Meyering, 2012/12/13
- Re: readlink(1) of more than one file?, Pádraig Brady, 2012/12/13
- Re: readlink(1) of more than one file?, Pádraig Brady, 2012/12/14
- Re: readlink(1) of more than one file?, Jim Meyering, 2012/12/14
- Re: readlink(1) of more than one file?, Bernhard Voelker, 2012/12/15
- Re: readlink(1) of more than one file?, Pádraig Brady, 2012/12/15
- Re: readlink(1) of more than one file?, Dmitry V. Levin, 2012/12/15
- Re: readlink(1) of more than one file?, Pádraig Brady, 2012/12/15
- Re: readlink(1) of more than one file?,
Pádraig Brady <=