@@ -113,6 +113,16 @@ set_composer_env() {
113113 fi
114114}
115115
116+ # Function to identify latest-like URLs that should bypass the persistent cache.
117+ is_mutable_tool_url () {
118+ local tool_url=$1
119+ local mutable_url_regex=' (^|[/?#._=-])(latest|stable|preview|snapshot|nightly|master)([/?#._=-]|$)|/releases/latest/download/'
120+ local version_like_regex=' (^|[^0-9])[0-9]+\.[0-9]+([.-][0-9A-Za-z]+)*'
121+ [[ " $tool_url " =~ $mutable_url_regex ]] && return 0
122+ [[ " $tool_url " =~ \. phar([? # ].*)?$ && ! "$tool_url" =~ $version_like_regex ]] && return 0
123+ return 1
124+ }
125+
116126# Helper function to configure tools.
117127add_tools_helper () {
118128 tool=$1
@@ -184,8 +194,10 @@ add_tool() {
184194 IFS=" ," read -r -a url <<< " $url"
185195 cache_key=$( get_sha256 " ${url[0]} " | head -c 16)
186196 cache_path=" $tool_cache_path_dir /${tool} -${cache_key} "
197+ use_cache=true
198+ is_mutable_tool_url " ${url[0]} " && use_cache=false
187199 status_code=" 200"
188- if [ -f " $cache_path " ]; then
200+ if [ " $use_cache " = " true " ] && [ -f " $cache_path " ]; then
189201 sudo cp -a " $cache_path " " $tool_path "
190202 else
191203 [ -f " $tool_path " ] && sudo cp -a " $tool_path " " $tool_path .bak"
@@ -194,7 +206,7 @@ add_tool() {
194206 url[0]=" ${url[0]// releases\/ latest\/ download/ releases/ download/ $(get -s -n " " " $( echo " ${url[0]} " | cut -d ' /' -f ' 1-5' ) /releases" | grep -Eo -m 1 " ([0-9]+\.[0-9]+\.[0-9]+)/$( echo " ${url[0]} " | sed -e " s/.*\///" ) " | cut -d ' /' -f 1)} "
195207 status_code=$( get -v -e " $tool_path " " ${url[0]} " )
196208 fi
197- if [ " $status_code " = " 200" ]; then
209+ if [ " $status_code " = " 200" ] && [ " $use_cache " = " true " ] ; then
198210 sudo cp -a " $tool_path " " $cache_path "
199211 elif [ -f " $tool_path .bak" ]; then
200212 sudo mv " $tool_path .bak" " $tool_path "
0 commit comments