From 407512ed5e97067501e74cf05022dfcc87a2bce0 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Thu, 15 Jun 2023 20:13:06 -0300 Subject: [PATCH] Only fetch container data when necessary --- docker | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docker b/docker index 6929f87..3c1fa03 100755 --- a/docker +++ b/docker @@ -31,11 +31,6 @@ function set_container_volumes() { readarray -t container_volumes <<<"${docker_output}" } -container_id="$(get_container_id)" -container_root_dir="$(get_container_root_dir "${container_id}")" -set_container_volumes "${container_id}" -readonly container_id container_root_dir container_volumes - function fix_volume_arg() { local source="${volume_arg%%":"*}" local destination="${volume_arg#*":"}" @@ -46,6 +41,14 @@ function fix_volume_arg() { # fi if [[ "${source}" == "/"* ]]; then + if [[ "${container_data_fetched}" == false ]]; then + container_id="$(get_container_id)" + container_root_dir="$(get_container_root_dir "${container_id}")" + set_container_volumes "${container_id}" + readonly container_id container_root_dir container_volumes + container_data_fetched=true + fi + for container_volume in "${container_volumes[@]}"; do local container_volume_source="${container_volume%%":"*}" local container_volume_destination="${container_volume#*":"}" @@ -175,6 +178,7 @@ for i in "${!original_args[@]}"; do fi done +container_data_fetched=false fixed_args=() extra_args=() fix_next_arg=false