diff mbox

[ovs-dev] ovs-vsctl-bashcomp: Make compatible with busybox "awk".

Message ID 20170714044254.23293-1-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff July 14, 2017, 4:42 a.m. UTC
It seems that awk in busybox doesn't think that an empty string is part of
a larger string, but that GNU awk does.  This commit adds an extra test to
make _ovs_vsctl_check_startswith_string work either way.

This allows the following tests to pass with busybox awk:

vsctl bashcomp unit tests

  7: vsctl-bashcomp - basic verification             ok
  8: vsctl-bashcomp - argument completion            ok

Reported-by: Stuart Cardall <developer@it-offshore.co.uk>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 utilities/ovs-vsctl-bashcomp.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ben Pfaff Aug. 2, 2017, 8:39 p.m. UTC | #1
This still needs a review.  Anyone?

On Thu, Jul 13, 2017 at 09:42:54PM -0700, Ben Pfaff wrote:
> It seems that awk in busybox doesn't think that an empty string is part of
> a larger string, but that GNU awk does.  This commit adds an extra test to
> make _ovs_vsctl_check_startswith_string work either way.
> 
> This allows the following tests to pass with busybox awk:
> 
> vsctl bashcomp unit tests
> 
>   7: vsctl-bashcomp - basic verification             ok
>   8: vsctl-bashcomp - argument completion            ok
> 
> Reported-by: Stuart Cardall <developer@it-offshore.co.uk>
> Signed-off-by: Ben Pfaff <blp@ovn.org>
> ---
>  utilities/ovs-vsctl-bashcomp.bash | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/utilities/ovs-vsctl-bashcomp.bash b/utilities/ovs-vsctl-bashcomp.bash
> index a3273f8eec4f..fc8245bfb553 100755
> --- a/utilities/ovs-vsctl-bashcomp.bash
> +++ b/utilities/ovs-vsctl-bashcomp.bash
> @@ -47,7 +47,7 @@ declare -A _OVS_VSCTL_NEW_RECORDS
>  # the input; this behaves like 'grep "^$1"' but deals with regex
>  # metacharacters in $1.
>  _ovs_vsctl_check_startswith_string () {
> -    awk 'index($0, thearg)==1' thearg="$1"
> +    awk 'thearg == "" || index($0, thearg)==1' thearg="$1"
>  }
>  
>  # $1 = word to complete on.
> -- 
> 2.10.2
>
Lance Richardson Aug. 4, 2017, 1:54 p.m. UTC | #2
> From: "Ben Pfaff" <blp@ovn.org>
> To: dev@openvswitch.org
> Cc: "Ben Pfaff" <blp@ovn.org>, "Stuart Cardall" <developer@it-offshore.co.uk>
> Sent: Friday, 14 July, 2017 12:42:54 AM
> Subject: [ovs-dev] [PATCH] ovs-vsctl-bashcomp: Make compatible with busybox	"awk".
> 
> It seems that awk in busybox doesn't think that an empty string is part of
> a larger string, but that GNU awk does.  This commit adds an extra test to
> make _ovs_vsctl_check_startswith_string work either way.
> 
> This allows the following tests to pass with busybox awk:
> 
> vsctl bashcomp unit tests
> 
>   7: vsctl-bashcomp - basic verification             ok
>   8: vsctl-bashcomp - argument completion            ok
> 
> Reported-by: Stuart Cardall <developer@it-offshore.co.uk>
> Signed-off-by: Ben Pfaff <blp@ovn.org>
> ---

Makes sense, verified that these test cases now pass in the Alpine
environment with busybox awk.

Acked-by: Lance Richardson <lrichard@redhat.com>
Ben Pfaff Aug. 9, 2017, 6:36 p.m. UTC | #3
On Fri, Aug 04, 2017 at 09:54:26AM -0400, Lance Richardson wrote:
> > From: "Ben Pfaff" <blp@ovn.org>
> > To: dev@openvswitch.org
> > Cc: "Ben Pfaff" <blp@ovn.org>, "Stuart Cardall" <developer@it-offshore.co.uk>
> > Sent: Friday, 14 July, 2017 12:42:54 AM
> > Subject: [ovs-dev] [PATCH] ovs-vsctl-bashcomp: Make compatible with busybox	"awk".
> > 
> > It seems that awk in busybox doesn't think that an empty string is part of
> > a larger string, but that GNU awk does.  This commit adds an extra test to
> > make _ovs_vsctl_check_startswith_string work either way.
> > 
> > This allows the following tests to pass with busybox awk:
> > 
> > vsctl bashcomp unit tests
> > 
> >   7: vsctl-bashcomp - basic verification             ok
> >   8: vsctl-bashcomp - argument completion            ok
> > 
> > Reported-by: Stuart Cardall <developer@it-offshore.co.uk>
> > Signed-off-by: Ben Pfaff <blp@ovn.org>
> > ---
> 
> Makes sense, verified that these test cases now pass in the Alpine
> environment with busybox awk.
> 
> Acked-by: Lance Richardson <lrichard@redhat.com>

Thanks for the review.  I applied this to master and branch-2.8.
diff mbox

Patch

diff --git a/utilities/ovs-vsctl-bashcomp.bash b/utilities/ovs-vsctl-bashcomp.bash
index a3273f8eec4f..fc8245bfb553 100755
--- a/utilities/ovs-vsctl-bashcomp.bash
+++ b/utilities/ovs-vsctl-bashcomp.bash
@@ -47,7 +47,7 @@  declare -A _OVS_VSCTL_NEW_RECORDS
 # the input; this behaves like 'grep "^$1"' but deals with regex
 # metacharacters in $1.
 _ovs_vsctl_check_startswith_string () {
-    awk 'index($0, thearg)==1' thearg="$1"
+    awk 'thearg == "" || index($0, thearg)==1' thearg="$1"
 }
 
 # $1 = word to complete on.