iotests: Drop readlink -f
PATCH v3 1/1 iotests: Drop readlink -f
On macOS, (out of the box) readlink does not have -f. We do not really need readlink here, though, it was just a replacement for realpath (which is not available on our BSD test systems), which we needed to make the $(dirname) into an absolute path.
Instead of using either, just use "cd; pwd" like is done for $source_iotests.
("iotests: Allow running from different directory")
--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/check +1 -1
@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$(readlink -f $(dirname "$0")) + build_iotests=$(cd "$(dirname "$0")"; pwd) else # called from the source tree source_iotests=$PWD
Signature · 1 line
2.26.2
Quoted 23 lines · Max Reitz
On macOS, (out of the box) readlink does not have -f. We do not really need readlink here, though, it was just a replacement for realpath (which is not available on our BSD test systems), which we needed to make the $(dirname) into an absolute path.
Instead of using either, just use "cd; pwd" like is done for $source_iotests.
Fixes b1cbc33a3971b6bb005d5ac3569feae35a71de0f("iotests: Allow running from different directory")
Suggested-by Peter Maydell <[email protected]>Reported-by Claudio Fontana <[email protected]>Reported-by Thomas Huth <[email protected]>Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qemu-iotests/check +0
-0
tests/qemu-iotests/check then · line 47
Quoted 5 lines
tests/qemu-iotests/check +1
-1@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$(readlink -f $(dirname "$0")) + build_iotests=$(cd "$(dirname "$0")"; pwd)
I assume the nested quotes are ok here? ... shell scripts always confuse me in that regard...
Thomas
Quoted 20 lines · Thomas Huth
Quoted 18 lines · Max Reitz
On macOS, (out of the box) readlink does not have -f. We do not really need readlink here, though, it was just a replacement for realpath (which is not available on our BSD test systems), which we needed to make the $(dirname) into an absolute path.
Instead of using either, just use "cd; pwd" like is done for $source_iotests.
Fixes b1cbc33a3971b6bb005d5ac3569feae35a71de0f("iotests: Allow running from different directory")
Suggested-by Peter Maydell <[email protected]>Reported-by Claudio Fontana <[email protected]>Reported-by Thomas Huth <[email protected]>Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
tests/qemu-iotests/check then · line 47
Quoted 10 lines
tests/qemu-iotests/check +1
-1@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$(readlink -f $(dirname "$0")) + build_iotests=$(cd "$(dirname "$0")"; pwd)I assume the nested quotes are ok here? ... shell scripts always confuse me in that regard...
Yes, the quoting is right here
(cf https://unix.stackexchange.com/questions/118433/quoting-within-command-substitution-in-bash)
-- $() creates a new quoting context and within it you quote
the command the same way you would if it were a standalone
commandline.
thanks
-- PMM
Quoted 10 lines · Thomas Huth
tests/qemu-iotests/check then · line 47
Quoted 7 lines
+++ b/tests/qemu-iotests/check
tests/qemu-iotests/check +1
-1@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$(readlink -f $(dirname "$0")) + build_iotests=$(cd "$(dirname "$0")"; pwd)I assume the nested quotes are ok here? ... shell scripts always confuse me in that regard...
Yes. Anything inside $() is a standalone script. That's one of the reasons that $() is nicer than `` (where you did indeed have to worry about " inside `` interfering with "``" on the outside, in some shells).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 23 lines · Max Reitz
On macOS, (out of the box) readlink does not have -f. We do not really need readlink here, though, it was just a replacement for realpath (which is not available on our BSD test systems), which we needed to make the $(dirname) into an absolute path.
Instead of using either, just use "cd; pwd" like is done for $source_iotests.
Fixes b1cbc33a3971b6bb005d5ac3569feae35a71de0f("iotests: Allow running from different directory")
Suggested-by Peter Maydell <[email protected]>Reported-by Claudio Fontana <[email protected]>Reported-by Thomas Huth <[email protected]>Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qemu-iotests/check +0
-0
tests/qemu-iotests/check then · line 47
Quoted 5 lines
tests/qemu-iotests/check +1
-1@@ -44,7 +44,7 @@ then _init_error "failed to obtain source tree name from check symlink" fi source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree" - build_iotests=$(readlink -f $(dirname "$0")) + build_iotests=$(cd "$(dirname "$0")"; pwd)
If CDPATH is set, this can produce wrong results. Do we care? Probably not, since (as you point out), $source_iotests has the same bug, and no one has complained yet.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 3 lines · Eric Blake
If CDPATH is set, this can produce wrong results. Do we care? Probably not, since (as you point out), $source_iotests has the same bug, and no one has complained yet.
This has come up previously -- configure and probably most of our other shell scripts will also break in the presence of CDPATH. I stand by my position that CDPATH is a bad misfeature that the shell should not be applying to scripts. If anybody ever reports a bug we could I suppose unconditionally unset CDPATH at the top of all our scripts.
thanks
-- PMM