diff --git a/plat/unix/update_gtags.sh b/plat/unix/update_gtags.sh index 0d2d2ec..516a7c3 100755 --- a/plat/unix/update_gtags.sh +++ b/plat/unix/update_gtags.sh @@ -5,6 +5,9 @@ set -e PROG_NAME=$0 GTAGS_EXE=gtags FILE_LIST_CMD= +TAGS_FILES="GTAGS GPATH GRTAGS" +GTAGS_PATHARG="${!#}" # last arg is always the path +LOCKFILE="$GTAGS_PATHARG/gtags.lock" ShowUsage() { echo "Usage:" @@ -30,7 +33,7 @@ while [[ $# -ne 0 ]]; do shift 2 ;; *) - GTAGS_ARGS="$GTAGS_ARGS $1" + GTAGS_ARGS="$GTAGS_ARGS $(printf %q "$1")" shift ;; esac @@ -42,7 +45,24 @@ else CMD="$GTAGS_EXE $GTAGS_ARGS" fi +echo "Locking gtags files..." +set -C +echo $$ > "$LOCKFILE" + +# Remove lock and any partial files on script exit +trap '\ +errorcode=$?; \ +for f in $TAGS_FILES; \ +do rm -f "$GTAGS_PATHARG/$f"; done; \ +rm -f "$LOCKFILE"; \ +exit $errorcode; \ +' INT QUIT TERM + echo "Running gtags:" echo "$CMD" eval "$CMD" + +echo "Unlocking gtags file..." +rm -f "$LOCKFILE" + echo "Done." diff --git a/plat/unix/update_pyscopedb.sh b/plat/unix/update_pyscopedb.sh index 8075d2e..c585d2d 100755 --- a/plat/unix/update_pyscopedb.sh +++ b/plat/unix/update_pyscopedb.sh @@ -51,6 +51,7 @@ if [ "$1" != "" ]; then fi echo "Locking pycscope DB file..." +set -C echo $$ > "$DB_FILE.lock" # Remove lock and temp file if script is stopped unexpectedly. diff --git a/plat/unix/update_scopedb.sh b/plat/unix/update_scopedb.sh index b66d586..7d770ed 100755 --- a/plat/unix/update_scopedb.sh +++ b/plat/unix/update_scopedb.sh @@ -54,9 +54,6 @@ if [ "$1" != "" ]; then exit 1 fi -echo "Locking cscope DB file..." -echo $$ > "$DB_FILE.lock" - # Remove lock and temp file if script is stopped unexpectedly. CleanUp() { rm -f "$DB_FILE.lock" "$DB_FILE.files" "$DB_FILE.temp" @@ -65,6 +62,10 @@ CleanUp() { fi } +echo "Locking cscope DB file..." +set -C +echo $$ > "$DB_FILE.lock" + trap CleanUp INT QUIT TERM EXIT PREVIOUS_DIR=$(pwd) diff --git a/plat/unix/update_tags.sh b/plat/unix/update_tags.sh index 9c1a24b..877e769 100755 --- a/plat/unix/update_tags.sh +++ b/plat/unix/update_tags.sh @@ -89,6 +89,7 @@ if [ "$1" != "" ]; then fi echo "Locking tags file..." +set -C echo $$ > "$TAGS_FILE.lock" # Remove lock and temp file if script is stopped unexpectedly.