Skip to contentSkip to conversation

PublishArtifacts.py: fix file check to work under dash

PATCH In review Bill Randle 2 participants 3 messages Aug 20, 2016 – Aug 22, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PublishArtifacts.py: fix file check to work under dash

An earlier patch (ed3857990) to check for existing msd5sum files worked fine when tested under bash, but failed with an error message about [[ not found when run under dash. Updated the test to not rely on bashisms.

---
 lib/python2.7/site-packages/autobuilder/buildsteps/PublishArtifacts.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/python2.7/site-packages/autobuilder/buildsteps/PublishArtifacts.py +2 -1
index d8b554f..58048f0 100644
@@ -259,8 +259,9 @@ class PublishArtifacts(ShellCommand):
     def generateMD5cmd(self, artifact, deploy_dir):
         cmd = ""
         if os.environ.get('GEN_IMG_MD5') == "True":
+            # crufty test for existing md5sum file required for dash shell
             cmd += "for x in `find " + deploy_dir + " -maxdepth 5 -type f`;"
-            cmd += "do if [[ $x != *.md5sum ]]; then md5sum $x >> " + "$x.md5sum; fi; done;"
+            cmd += "do echo ${x} | grep -q '\.md5sum'; if [ $? -ne 0 ]; then md5sum $x >> " + "$x.md5sum; fi; done;"
         return cmd
 
     def getDeployNames(self, artifact, buildername):
Signature · 1 line
2.5.5
#1 lore raw
Quoted 27 lines · Bill Randle

An earlier patch (ed3857990) to check for existing msd5sum files worked
fine when tested under bash, but failed with an error message about [[
not found when run under dash. Updated the test to not rely on bashisms.

---
 lib/python2.7/site- packages/autobuilder/buildsteps/PublishArtifacts.py | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

packages/autobuilder/buildsteps/PublishArtifacts.py b/lib/python2.7/site- packages/autobuilder/buildsteps/PublishArtifacts.py index d8b554f..58048f0 100644
--- a/lib/python2.7/site- packages/autobuilder/buildsteps/PublishArtifacts.py +++ b/lib/python2.7/site- packages/autobuilder/buildsteps/PublishArtifacts.py

(quoted diff) +0 -0
@@ -259,8 +259,9 @@ class PublishArtifacts(ShellCommand):

     def generateMD5cmd(self, artifact, deploy_dir):
         cmd = ""
         if os.environ.get('GEN_IMG_MD5') == "True":
+            # crufty test for existing md5sum file required for dash

Quoted 8 lines

shell
             cmd += "for x in find " + deploy_dir + " -maxdepth 5 -type f;"
-            cmd += "do if [[ $x != *.md5sum ]]; then md5sum $x >> "
+ "$x.md5sum; fi; done;"
+            cmd += "do echo ${x} | grep -q '\.md5sum'; if [ $? -ne 0 ]; then md5sum $x >> " + "$x.md5sum; fi; done;"
         return cmd

Rather than a "crufty" test, how about using POSIX sh parameter expansion, i.e.

$ foo="blah.bar"
$ if [ ${foo##*.} == bar ]; then echo "bar!"; fi
bar!

Therefore, the patch would be something like (untested):

cmd += "if [ ${x##*.} == .md5sum ]; then md5sum $x >> $x.md5sum; fi"

Regards,

Joshua

Quoted 2 lines


     def getDeployNames(self, artifact, buildername):

#2 lore raw

On Mon, 2016-08-22 at 11:28 +0100, Joshua Lock wrote:

On Sat, 2016-08-20 at 15:50 -0700, Bill Randle wrote:

An earlier patch (ed3857990) to check for existing msd5sum files worked
fine when tested under bash, but failed with an error message about [[
not found when run under dash. Updated the test to not rely on bashisms.

---
lib/python2.7/site-
packages/autobuilder/buildsteps/PublishArtifacts.py | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

packages/autobuilder/buildsteps/PublishArtifacts.py b/lib/python2.7/site- packages/autobuilder/buildsteps/PublishArtifacts.py index d8b554f..58048f0 100644
--- a/lib/python2.7/site- packages/autobuilder/buildsteps/PublishArtifacts.py +++ b/lib/python2.7/site- packages/autobuilder/buildsteps/PublishArtifacts.py @@ -259,8 +259,9 @@ class PublishArtifacts(ShellCommand):

     def generateMD5cmd(self, artifact, deploy_dir):
         cmd = ""
         if os.environ.get('GEN_IMG_MD5') == "True":
+            # crufty test for existing md5sum file required for dash
shell
             cmd += "for x in `find " + deploy_dir + " -maxdepth 5

-type f`;"
- cmd += "do if [[ $x != *.md5sum ]]; then md5sum $x >> "
+ "$x.md5sum; fi; done;"
+ cmd += "do echo ${x} | grep -q '\.md5sum'; if [ $? -ne 0
]; then md5sum $x >> " + "$x.md5sum; fi; done;"
return cmd

Rather than a "crufty" test, how about using POSIX sh parameter expansion, i.e.

$ foo="blah.bar"
$ if [ ${foo##*.} == bar ]; then echo "bar!"; fi
bar!

Therefore, the patch would be something like (untested):

cmd += "if [ ${x##*.} == .md5sum ]; then md5sum $x >> $x.md5sum; fi"

Regards,

Joshua

Good suggestion! The correct (tested) patch would be:
if [ ${x##*.} != md5sum ]; then md5sum $x >> $x.md5sum; fi"

Updated patch coming shortly.

-Bill