Remote file exists bug
Simon Marchi <[email protected]> Mon, 11 Jan 2016 16:04:34 -0500
| Newsgroups | gmane.comp.sysutils.dejagnu.bugs |
|---|---|
| Message-ID | <CAFXXi0k5k2tsViErg0AEvBQey_bPJPLsEYwuNhvDD_4q0+Zs+Q@mail.gmail.com> |
Hi,
I tried using:
remote_file target exists $file
with a remote target, and noticed it would always return true,
regardless if the file actually exists. The test done to implement
this is the following (found at remote.exp:769):
set status [remote_exec $dest "sh -c 'exit `\[ -f $file \]`'"]
The intent of the code is clear: it expects "[ -f $file ]" to output 1
or 0, depending on if the file actually exists. That would give "exit
1" or "exit 0", giving us the result of our test.
However, the [ operator does not actually output anything, it returns
1 or 0 as its exit code. So the outcome is always simply "exit",
which is equivalent to "exit 0", which is always true. As an
alternative, I suggest calling the "test" utility (which is present on
all unixes I know about) and use its exit code directly:
set status [remote_exec $dest "test -f $file"]
I attached a patch that implements this change. What do you think?
Thanks
Simon
_______________________________________________
Bug-dejagnu mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-dejagnu
0001-Fix-remote-file-exists-check.patch
(text/x-patch, 693 B)
From 9d95ea2f1fa6dbf5da8c3fc3752dfa11332e9eb8 Mon Sep 17 00:00:00 2001 From: Simon Marchi <[email protected]> Date: Mon, 11 Jan 2016 15:29:47 -0500 Subject: [PATCH] Fix remote file exists check --- lib/remote.exp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/remote.exp b/lib/remote.exp index fb040bb..bddf2ae 100644 --- a/lib/remote.exp +++ b/lib/remote.exp @@ -765,8 +765,7 @@ proc standard_file { dest op args } { } switch $op { exists { - # mmmm, quotes. - set status [remote_exec $dest "sh -c 'exit `\[ -f $file \]`'"] + set status [remote_exec $dest "test -f $file"] return [lindex $status 0] } delete { -- 2.5.1