From 100b49c84dbfad4859f8d972aea642af9e83a62c Mon Sep 17 00:00:00 2001 From: Filippo Squillace Date: Thu, 28 Jul 2022 00:07:15 +0200 Subject: [PATCH] #297 Create bin wrapper for symlinks --- lib/core/wrappers.sh | 7 +++++-- tests/unit-tests/test-wrappers.sh | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/core/wrappers.sh b/lib/core/wrappers.sh index da5517f..243319f 100644 --- a/lib/core/wrappers.sh +++ b/lib/core/wrappers.sh @@ -25,7 +25,10 @@ function create_wrappers() { cd "${JUNEST_HOME}/usr/bin" || return 1 for file in * do - [[ -x $file ]] || continue + [[ -d $file ]] && continue + # Symlinks outside junest appear as broken even though the are correct + # within a junest session. The following do not skip broken symlinks: + [[ -x $file || -L $file ]] || continue if [[ -e ${JUNEST_HOME}/usr/bin_wrappers/$file ]] && ! $force then continue @@ -47,7 +50,7 @@ EOF cd "${JUNEST_HOME}/usr/bin_wrappers" || return 1 for file in * do - [[ -e ${JUNEST_HOME}/usr/bin/$file ]] || rm -f "$file" + [[ -e ${JUNEST_HOME}/usr/bin/$file || -L ${JUNEST_HOME}/usr/bin/$file ]] || rm -f "$file" done } diff --git a/tests/unit-tests/test-wrappers.sh b/tests/unit-tests/test-wrappers.sh index af7aae2..47e7a65 100755 --- a/tests/unit-tests/test-wrappers.sh +++ b/tests/unit-tests/test-wrappers.sh @@ -34,6 +34,22 @@ function test_create_wrappers_not_executable_file(){ assertTrue "myfile wrapper should not exist" "[ ! -x $JUNEST_HOME/usr/bin_wrappers/myfile ]" } +function test_create_wrappers_directory(){ + mkdir -p "$JUNEST_HOME"/usr/bin/mydir + assertCommandSuccess create_wrappers + assertEquals "" "$(cat "$STDOUTF")" + assertTrue "bin_wrappers should exist" "[ -e $JUNEST_HOME/usr/bin_wrappers ]" + assertTrue "mydir wrapper should not exist" "[ ! -e $JUNEST_HOME/usr/bin_wrappers/mydir ]" +} + +function test_create_wrappers_broken_link(){ + ln -s /opt/myapp/bin/cmd "$JUNEST_HOME"/usr/bin/cmd + assertCommandSuccess create_wrappers + assertEquals "" "$(cat "$STDOUTF")" + assertTrue "bin_wrappers should exist" "[ -e $JUNEST_HOME/usr/bin_wrappers ]" + assertTrue "cmd wrapper should exist" "[ -x $JUNEST_HOME/usr/bin_wrappers/cmd ]" +} + function test_create_wrappers_executable_file(){ touch "$JUNEST_HOME"/usr/bin/myfile chmod +x "$JUNEST_HOME"/usr/bin/myfile