From b6b80749140aec6ae75e5568a5defd905196d5f2 Mon Sep 17 00:00:00 2001 From: mattyo161 Date: Wed, 10 Jan 2024 08:10:30 -0500 Subject: [PATCH] perf: only create dirs if they do not already exist (#1566) Co-authored-by: Matt Ouellette --- bin/asdf | 4 ++++ lib/functions/plugins.bash | 2 +- lib/utils.bash | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/asdf b/bin/asdf index 4a15f61f0..439fd1814 100755 --- a/bin/asdf +++ b/bin/asdf @@ -1,5 +1,9 @@ #!/usr/bin/env bash + set -o pipefail +if [[ "${ASDF_DEBUG}" == "1" ]]; then + set -x +fi # shellcheck source=lib/utils.bash . "$(dirname "$(dirname "$0")")/lib/utils.bash" diff --git a/lib/functions/plugins.bash b/lib/functions/plugins.bash index 3b36ddd9c..6f7a9435c 100644 --- a/lib/functions/plugins.bash +++ b/lib/functions/plugins.bash @@ -76,7 +76,7 @@ plugin_add_command() { local plugin_path plugin_path=$(get_plugin_path "$plugin_name") - mkdir -p "$(asdf_data_dir)/plugins" + [ -d "$(asdf_data_dir)/plugins" ] || mkdir -p "$(asdf_data_dir)/plugins" if [ -d "$plugin_path" ]; then printf '%s\n' "Plugin named $plugin_name already added" diff --git a/lib/utils.bash b/lib/utils.bash index 8eae18fcb..21978a929 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -62,7 +62,7 @@ get_install_path() { local install_dir install_dir="$(asdf_data_dir)/installs" - mkdir -p "${install_dir}/${plugin}" + [ -d "${install_dir}/${plugin}" ] || mkdir -p "${install_dir}/${plugin}" if [ "$install_type" = "version" ]; then printf "%s/%s/%s\n" "$install_dir" "$plugin" "$version" @@ -81,7 +81,7 @@ get_download_path() { local download_dir download_dir="$(asdf_data_dir)/downloads" - mkdir -p "${download_dir}/${plugin}" + [ -d "${download_dir}/${plugin}" ] || mkdir -p "${download_dir}/${plugin}" if [ "$install_type" = "version" ]; then printf "%s/%s/%s\n" "$download_dir" "$plugin" "$version" @@ -442,7 +442,7 @@ initialize_or_update_plugin_repository() { git -C "$repository_path" reset --hard origin/master fi - mkdir -p "$(asdf_data_dir)/tmp" + [ -d "$(asdf_data_dir)/tmp" ] || mkdir -p "$(asdf_data_dir)/tmp" touch "$(asdf_data_dir)/tmp/repo-updated" }