From 978344a55cdc950f4547de165041736ffc7a2e53 Mon Sep 17 00:00:00 2001 From: Felix Lohmeier Date: Sun, 5 Nov 2017 18:09:41 +0100 Subject: [PATCH] release v1.10, safe cleanup handler issue #4 --- openrefine-batch-docker.sh | 32 ++++++++++++++++++++------------ openrefine-batch.sh | 32 ++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/openrefine-batch-docker.sh b/openrefine-batch-docker.sh index a79b6bf..e20bb42 100755 --- a/openrefine-batch-docker.sh +++ b/openrefine-batch-docker.sh @@ -1,5 +1,5 @@ #!/bin/bash -# openrefine-batch-docker.sh, Felix Lohmeier, v1.9, 2017-11-05 +# openrefine-batch-docker.sh, Felix Lohmeier, v1.10, 2017-11-05 # https://github.com/felixlohmeier/openrefine-batch # check system requirements @@ -128,6 +128,10 @@ if [ -z "$outputdir" ]; then echo 1>&2 "example: ./openrefine-batch-docker.sh -c output/" exit 1 fi +if [ "$(ls -A "$outputdir" 2>/dev/null)" ];then + echo 1>&2 "path to directory for exported files (and OpenRefine workspace) is not empty" + exit 1 +fi if [ "$format" = "xml" ] || [ "$format" = "json" ] && [ -z "$inputoptions" ]; then echo 1>&2 "error: you specified the inputformat $format but did not provide mandatory input options" echo 1>&2 "please provide recordpath in multiple arguments without slashes" @@ -173,6 +177,21 @@ checkpointdate[$((checkpoints + 1))]=$(date +%s) checkpointname[$((checkpoints + 1))]="Start process" memoryload=() +# safe cleanup handler +cleanup() +{ + echo "" + echo "cleanup..." + docker stop -t=5000 ${uuid} + docker rm ${uuid} + rm -r -f "${outputdir:?}"/workspace*.json + # delete duplicates from copied projects + if [ -n "$crossprojects" ]; then + for i in "${crossprojects[@]}" ; do rm -r -f "${outputdir}/${i}" ; done + fi +} +trap cleanup EXIT + # launch server checkpoints=${#checkpointdate[@]} checkpointdate[$((checkpoints + 1))]=$(date +%s) @@ -325,17 +344,6 @@ if [ -n "$jsonfiles" ] || [ "$export" = "true" ]; then fi fi -# cleanup -echo "cleanup..." -docker stop -t=5000 ${uuid} -docker rm ${uuid} -rm -r -f "${outputdir:?}"/workspace*.json -# delete duplicates from copied projects -if [ -n "$crossprojects" ]; then - for i in "${crossprojects[@]}" ; do rm -r -f "${outputdir}/${i}" ; done -fi -echo "" - # calculate and print checkpoints echo "=== Statistics ===" echo "" diff --git a/openrefine-batch.sh b/openrefine-batch.sh index ba8326f..5847d32 100755 --- a/openrefine-batch.sh +++ b/openrefine-batch.sh @@ -1,5 +1,5 @@ #!/bin/bash -# openrefine-batch.sh, Felix Lohmeier, v1.9, 2017-11-05 +# openrefine-batch.sh, Felix Lohmeier, v1.10, 2017-11-05 # https://github.com/felixlohmeier/openrefine-batch # declare download URLs for OpenRefine and OpenRefine client @@ -153,6 +153,10 @@ if [ -z "$outputdir" ]; then echo 1>&2 "example: ./openrefine-batch.sh -c output/" exit 1 fi +if [ "$(ls -A "$outputdir" 2>/dev/null)" ];then + echo 1>&2 "path to directory for exported files (and OpenRefine workspace) is not empty" + exit 1 +fi if [ "$format" = "xml" ] || [ "$format" = "json" ] && [ -z "$inputoptions" ]; then echo 1>&2 "error: you specified the inputformat $format but did not provide mandatory input options" echo 1>&2 "please provide recordpath in multiple arguments without slashes" @@ -196,6 +200,21 @@ checkpointdate[$((checkpoints + 1))]=$(date +%s) checkpointname[$((checkpoints + 1))]="Start process" memoryload=() +# safe cleanup handler +cleanup() +{ + echo "" + echo "cleanup..." + kill ${pid} + wait + rm -r -f "${outputdir:?}"/workspace*.json + # delete duplicates from copied projects + if [ -n "$crossprojects" ]; then + for i in "${crossprojects[@]}" ; do rm -r -f "${outputdir}/${i}" ; done + fi +} +trap cleanup EXIT + # launch server checkpoints=${#checkpointdate[@]} checkpointdate[$((checkpoints + 1))]=$(date +%s) @@ -351,17 +370,6 @@ if [ -n "$jsonfiles" ] || [ "$export" = "true" ]; then fi fi -# cleanup -echo "cleanup..." -kill ${pid} -wait -rm -r -f "${outputdir:?}"/workspace*.json -# delete duplicates from copied projects -if [ -n "$crossprojects" ]; then - for i in "${crossprojects[@]}" ; do rm -r -f "${outputdir}/${i}" ; done -fi -echo "" - # calculate and print checkpoints echo "=== Statistics ===" echo ""