From f633811577b079815deff26ab8e2161770bb24a9 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Fri, 5 Feb 2021 11:26:02 -0500 Subject: [PATCH] Ban process substitution from asdf codebase --- lib/commands/command-plugin-update.bash | 3 ++- lib/commands/command-reshim.bash | 14 +++++++++++++- lib/utils.bash | 6 ++++-- test/banned_commands.bats | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/commands/command-plugin-update.bash b/lib/commands/command-plugin-update.bash index 2a9927a0..90cf5645 100644 --- a/lib/commands/command-plugin-update.bash +++ b/lib/commands/command-plugin-update.bash @@ -10,11 +10,12 @@ plugin_update_command() { local gitref="${2:-master}" if [ "$plugin_name" = "--all" ]; then if [ -d "$(asdf_data_dir)"/plugins ]; then + plugins=(find "$(asdf_data_dir)"/plugins -type d -mindepth 1 -maxdepth 1) while IFS= read -r -d '' dir; do local plugin_name plugin_name=$(basename "$dir") update_plugin "$plugin_name" "$dir" "$gitref" & - done < <(find "$(asdf_data_dir)"/plugins -type d -mindepth 1 -maxdepth 1) + done <<< "$plugins" wait fi else diff --git a/lib/commands/command-reshim.bash b/lib/commands/command-reshim.bash index 6f8638ba..ecb2a1ea 100644 --- a/lib/commands/command-reshim.bash +++ b/lib/commands/command-reshim.bash @@ -119,7 +119,19 @@ remove_obsolete_shims() { exec_names=$(plugin_executables "$plugin_name" "$full_version" | xargs -IX basename X | sort) local obsolete_shims - obsolete_shims=$(comm -23 <(printf "%s\\n" "$shims") <(printf "%s\\n" "$exec_names")) + local formatted_shims + local formatted_exec_names + + # comm only takes to files, so we write this data to temp files so we can + # pass it to comm. + formatted_shims=$(mktemp /tmp/asdf-command-reshim-formatted-shims.XXXXXX) + printf "%s\\n" "$shims" > "$formatted_shims" + + formatted_exec_names=$(mktemp /tmp/asdf-command-reshim-formatted-exec-names.XXXXXX) + printf "%s\\n" "$exec_names" > "$formatted_exec_names" + + obsolete_shims=$(comm -23 "$formatted_shims" "$formatted_exec_names") + rm -f "$formatted_exec_names" "$formatted_shims" for shim_name in $obsolete_shims; do remove_shim_for_version "$plugin_name" "$full_version" "$shim_name" diff --git a/lib/utils.bash b/lib/utils.bash index ce8360af..483adc5d 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -662,8 +662,10 @@ preset_versions() { } select_from_preset_version() { - shim_name=$1 - grep -f <(get_shim_versions "$shim_name") <(preset_versions "$shim_name") | head -n 1 | xargs -IVERSION printf "%s\\n" VERSION + local shim_name=$1 + local shim_versions=$(get_shim_versions "$shim_name") + local present_versions=$(preset_versions "$shim_name") + grep -f "$shim_versions" "$preset_versions" | head -n 1 | xargs -IVERSION printf "%s\\n" VERSION } select_version() { diff --git a/test/banned_commands.bats b/test/banned_commands.bats index a76fcca8..b17e4b83 100644 --- a/test/banned_commands.bats +++ b/test/banned_commands.bats @@ -19,6 +19,8 @@ banned_commands=( # echo isn't consistent across operating systems, and sometimes output can # be confused with echo flags. printf does everything echo does and more. echo + # Process substitution isn't POSIX compliant and cause trouble + "<(" ) setup() {