Skip to content

Commit

Permalink
More escaping
Browse files Browse the repository at this point in the history
Signed-off-by: Johnny Bieren <[email protected]>
  • Loading branch information
johnbieren committed May 8, 2018
1 parent 6571fec commit 247daf0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/org/centos/pipeline/PipelineUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1211,27 +1211,27 @@ def obtainLock(String fileLocation, int duration) {
def myuuid = sh (returnStdout: true, script: 'uuidgen').trim()

sh """
set -x
(
flock 9
currentTime=\$(date +%s)
while true ; do
# Check if lock file exists
while [ -f "${fileLocation}" ] ; do
lockAge=\$(stat -c %Y "${fileLocation}")
ageDiff=\$((${currentTime} - ${lockAge}))
ageDiff=\$((\${currentTime} - \${lockAge}))
# Break if lock file is too old
if [ ${ageDiff} -ge "${duration}" ]; then
if [ \${ageDiff} -ge "${duration}" ]; then
break
fi
sleep 30
currentTime=\$(date +%s)
done
# Now, either lock file is older than duration
# or the lock is gone, so proceed
echo ${myuuid} > "${fileLocation}"
echo "${myuuid}" > "${fileLocation}"
testuuid=\$(cat "${fileLocation}")
# If uuid matches, we got the lock
if [ ${testuuid} == ${myuuid} ]; then
if [ \${testuuid} == "${myuuid}" ]; then
break
fi
sleep 30
Expand All @@ -1250,7 +1250,7 @@ def obtainLock(String fileLocation, int duration) {
*/
def releaseLock(String fileLocation, String myuuid) {
if (fileExists(fileLocation)) {
def storeduuid = readFile(fileLocation)
def storeduuid = readFile(fileLocation).trim()
if (storeduuid == myuuid) {
sh "rm -f ${fileLocation}"
return
Expand Down

0 comments on commit 247daf0

Please sign in to comment.