Make sure target exists before running it

By generating the targets list once prior to running the targets, there
is the possibility that a script doesn't exist anymore or doesn't have
the right permissions by the time it is called.

See for instance [1] that deletes files from the target_dir.

This commit ensures the target exists and is executable before trying to
run it.

[1] 41ee9895d5/elements/hiera/os-refresh-config/configure.d/10-hiera-disable
Change-Id: I746b5c89082fedc01b32ad00e573a25f8c4201c0
This commit is contained in:
Martin André 2017-01-16 18:44:50 +01:00
parent 51661c33a5
commit 5481b77ecf
1 changed files with 3 additions and 1 deletions

View File

@ -116,7 +116,9 @@ PROFILE_DIR=$(mktemp -d --tmpdir profiledir.XXXXXX)
output "Running $target_dir/$target"
target_tag=${target//\//_}
date +%s.%N > $PROFILE_DIR/start_$target_tag
$target_dir/$target
if [ -x $target_dir/$target ]; then
$target_dir/$target
fi
target_tag=${target//\//_}
date +%s.%N > $PROFILE_DIR/stop_$target_tag
output "$target completed"