Skip to contentSkip to conversation

Fix bashism in fsck.btrfs for debian/ubuntu dash.

PATCH In review Dimitri John Ledkov 6 participants 11 messages May 15, 2015 – May 25, 2015 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix bashism in fsck.btrfs for debian/ubuntu dash.

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=784911

---
 fsck.btrfs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsck.btrfs +1 -1
index f056a7f..3a92804 100755
@@ -31,7 +31,7 @@ if [ ! -e $DEV ]; then
 	echo "$0: $DEV does not exist"
 	exit 8
 fi
-if [ "$AUTO" == "false" ]; then
+if [ "false" = "$AUTO" ]; then
 	echo "If you wish to check the consistency of a BTRFS filesystem or"
 	echo "repair a damaged filesystem, see btrfs(8) subcommand 'check'."
 fi
Signature · 1 line
2.1.4
#1 lore raw
Quoted 11 lines · Dimitri John Ledkov

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=784911

---
 fsck.btrfs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsck.btrfs +0 -0
index f056a7f..3a92804 100755

fsck.btrfs if [ ! -e $DEV ]; then · line 37

Quoted 8 lines
fsck.btrfs +1 -1
@@ -31,7 +31,7 @@ if [ ! -e $DEV ]; then
 	echo "$0: $DEV does not exist"
 	exit 8
 fi
-if [ "$AUTO" == "false" ]; then
+if [ "false" = "$AUTO" ]; then
 	echo "If you wish to check the consistency of a BTRFS filesystem or"
 	echo "repair a damaged filesystem, see btrfs(8) subcommand 'check'."
 fi

I'm going to completely bikeshed here, but Yoda conditions are already ugly in C, and completely pointless in Bash, where you can't ever accidentally reassign a variable in a condition. Either way, I think:

if [ ! $AUTO ]; then

would be clearer anyways.

Thanks!

Signature · 1 line
Omar
#2 lore raw

Am 15.05.2015 um 22:43 schrieb Omar Sandoval:

Quoted 7 lines

I'm going to completely bikeshed here, but Yoda conditions are already ugly in C, and completely pointless in Bash, where you can't ever accidentally reassign a variable in a condition. Either way, I think:

if [ ! $AUTO ]; then

would be clearer anyways.

Ah, I'm sorry to disagree with you, but your code snippet would only work if $AUTO is *empty*, and I think, to be totally correct you'd have to use the -n or -z test.

To sum it up now, you'd have to replace "false" with an empty string in the beginning of the file and the zero-test in the end. So something like the following:

AUTO=

# ...
if [ -z "$AUTO" ]; then

Regards
--Flo

#3 lore raw
Quoted 13 lines · Florian Gamböck

Am 15.05.2015 um 22:43 schrieb Omar Sandoval:

Quoted 7 lines

I'm going to completely bikeshed here, but Yoda conditions are already ugly in C, and completely pointless in Bash, where you can't ever accidentally reassign a variable in a condition. Either way, I think:

if [ ! $AUTO ]; then

would be clearer anyways.

Ah, I'm sorry to disagree with you, but your code snippet would only work if $AUTO is *empty*, and I think, to be totally correct you'd have to use the -n or -z test.

Quoted 8 lines

To sum it up now, you'd have to replace "false" with an empty string in the beginning of the file and the zero-test in the end. So something like the following:

AUTO=

# ...
if [ -z "$AUTO" ]; then

Whoops, you're totally right, that was a typo. I meant

if ! $AUTO; then

Signature · 1 line
Omar
#4 lore raw
Quoted 18 lines · Omar Sandoval
Quoted 17 lines · Florian Gamböck

Am 15.05.2015 um 22:43 schrieb Omar Sandoval:

Quoted 7 lines

I'm going to completely bikeshed here, but Yoda conditions are already ugly in C, and completely pointless in Bash, where you can't ever accidentally reassign a variable in a condition. Either way, I think:

if [ ! $AUTO ]; then

would be clearer anyways.

Ah, I'm sorry to disagree with you, but your code snippet would only work if $AUTO is *empty*, and I think, to be totally correct you'd have to use the -n or -z test.

To sum it up now, you'd have to replace "false" with an empty string in the beginning of the file and the zero-test in the end. So something like the following:

Quoted 8 lines
Quoted 4 lines

AUTO=

# ...
if [ -z "$AUTO" ]; then

Whoops, you're totally right, that was a typo. I meant

if ! $AUTO; then

That's my preference as it was implemented originally. I did not pay close attention to how it was implemented in "silence fake fsck" as far as it worked.

#5 lore raw
In reply to Florian Gamböck

If we just want to fix the bashism, then

        if [ "$AUTO" = "false" ]; then

is a good solution. No point to use a yoda condition.

But I like the style proposed by Florian best. It is closest to traditional shell programming.

Quoted 4 lines · Florian Gamböck

AUTO=

# ...
if [ -z "$AUTO" ]; then

Markus

Signature · 2 lines
Markus Baertschi, Bas du Rossé 16, CH-1163, Etoy, Switzerland
[email protected], +41 (79) 403 1186 (mobile)
#6 lore raw
In reply to Dimitri John Ledkov
Quoted 11 lines · Dimitri John Ledkov

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=784911

---
 fsck.btrfs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsck.btrfs +0 -0
index f056a7f..3a92804 100755

fsck.btrfs if [ ! -e $DEV ]; then · line 37

Quoted 8 lines
fsck.btrfs +1 -1
@@ -31,7 +31,7 @@ if [ ! -e $DEV ]; then
        echo "$0: $DEV does not exist"
        exit 8
 fi
-if [ "$AUTO" == "false" ]; then
+if [ "false" = "$AUTO" ]; then
        echo "If you wish to check the consistency of a BTRFS filesystem or"
        echo "repair a damaged filesystem, see btrfs(8) subcommand 'check'."
 fi

There was a lot of discussion about this trivial patch, mostly because it's so trivial and has many ways to fix.

I hope btrfs maintainers could implement & push any of the proposed ways to resolve this bashism to rule them all =)

Signature · 3 lines
Regards,

Dimitri.
#7 lore raw
Quoted 24 lines · Dimitri John Ledkov
Quoted 11 lines · Dimitri John Ledkov

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=784911

---
 fsck.btrfs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsck.btrfs +0 -0
index f056a7f..3a92804 100755

fsck.btrfs if [ ! -e $DEV ]; then · line 37

Quoted 8 lines
fsck.btrfs +1 -1
@@ -31,7 +31,7 @@ if [ ! -e $DEV ]; then
        echo "$0: $DEV does not exist"
        exit 8
 fi
-if [ "$AUTO" == "false" ]; then
+if [ "false" = "$AUTO" ]; then
        echo "If you wish to check the consistency of a BTRFS filesystem or"
        echo "repair a damaged filesystem, see btrfs(8) subcommand 'check'."
 fi

There was a lot of discussion about this trivial patch, mostly because it's so trivial and has many ways to fix.

Quoted 2 lines

I hope btrfs maintainers could implement & push any of the proposed ways to resolve this bashism to rule them all =)

If you're ok to do

if ! $AUTO...

with your signed-off, then I'll add the patch. I was not comfortable to do it right away.

#8 lore raw

PATCH 1/1 fsck.btrfs: Fix bashism and bad getopts processing

First fix == bashism, as that is not accepted by e.g. Debian/Ubuntu dash.

Secondly shift OPTIND, such that last parameter is checked to exist.

---
 fsck.btrfs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fsck.btrfs +2 -1
index f056a7f..20b070a 100755
@@ -26,12 +26,13 @@ do
 	a|A|p|y)	AUTO=true;;
 	esac
 done
+shift $(($OPTIND -1))
 eval DEV=\${$#}
 if [ ! -e $DEV ]; then
 	echo "$0: $DEV does not exist"
 	exit 8
 fi
-if [ "$AUTO" == "false" ]; then
+if ! $AUTO; then
 	echo "If you wish to check the consistency of a BTRFS filesystem or"
 	echo "repair a damaged filesystem, see btrfs(8) subcommand 'check'."
 fi
Signature · 1 line
2.1.4
Applied
#9 lore raw

Re: [PATCH] fsck.btrfs: Fix bashism and bad getopts processing

Quoted 6 lines · Dimitri John Ledkov

First fix == bashism, as that is not accepted by e.g. Debian/Ubuntu dash.

Secondly shift OPTIND, such that last parameter is checked to exist.

Applied, thanks.

#10 lore raw

Re: [PATCH] fsck.btrfs: Fix bashism and bad getopts processing

In reply to Dimitri John Ledkov
Quoted 15 lines · Dimitri John Ledkov

First fix == bashism, as that is not accepted by e.g. Debian/Ubuntu dash.

Secondly shift OPTIND, such that last parameter is checked to exist.

---
 fsck.btrfs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fsck.btrfs +0 -0
index f056a7f..20b070a 100755

fsck.btrfs do · line 29

Quoted 4 lines
fsck.btrfs +1 -0
@@ -26,12 +26,13 @@ do
 	a|A|p|y)	AUTO=true;;
 	esac
 done
+shift $(($OPTIND -1))

BTW, this line is missing in the fsck.xfs stub as well, you may want to send the patch to xfsprogs.