From 6c9d979be1435a0d852f2894b74ed10fdad4b789 Mon Sep 17 00:00:00 2001 From: Joachim Ansorg Date: Mon, 30 Dec 2024 18:00:13 +0100 Subject: [PATCH 1/2] Fix breakpoint not hit with relative path after script changed the working directory The current working directory of the debugged script must always be used as fallback, as it's the directory used by the script to locate files with a relative path. --- lib/filecache.sh | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/filecache.sh b/lib/filecache.sh index 3ee92a9..5c99b04 100644 --- a/lib/filecache.sh +++ b/lib/filecache.sh @@ -152,24 +152,25 @@ function _Dbg_is_file { echo "$try_find_file" return 0 fi - else - # Resolve file using _Dbg_dir - typeset -i n=${#_Dbg_dir[@]} - typeset -i i - for (( i=0 ; i < n; i++ )) ; do - typeset basename="${_Dbg_dir[i]}" - if [[ $basename == '\$cdir' ]] ; then - basename=$_Dbg_cdir - elif [[ $basename == '\$cwd' ]] ; then - basename=$(pwd) - fi - try_find_file="$basename/$find_file" - if [[ -f "$try_find_file" ]] ; then - echo "$try_find_file" - return 0 - fi - done fi + + # Resolve file using _Dbg_dir + typeset -i n=${#_Dbg_dir[@]} + typeset -i i + for (( i=0 ; i < n; i++ )) ; do + typeset basename="${_Dbg_dir[i]}" + if [[ $basename == '\$cdir' ]] ; then +basename=$_Dbg_cdir + elif [[ $basename == '\$cwd' ]] ; then +basename=$(pwd) + fi + try_find_file=$(_Dbg_expand_filename "$basename/$find_file") + if [[ -n ${_Dbg_filenames[$try_find_file]} ]] ; then + echo "$try_find_file" + return 0 + fi + done + echo '' return 1 } From b78910ad9efa514685dfd9e9c829949387422ec9 Mon Sep 17 00:00:00 2001 From: Joachim Ansorg Date: Mon, 30 Dec 2024 18:01:32 +0100 Subject: [PATCH 2/2] Quote a few more file paths --- lib/file.sh | 4 ++-- lib/filecache.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/file.sh b/lib/file.sh index 8eb667e..24c6d41 100644 --- a/lib/file.sh +++ b/lib/file.sh @@ -24,8 +24,8 @@ typeset -a _Dbg_dir _Dbg_dir=('\$cdir' '\$cwd' ) # _Dbg_cdir is the directory in which the script is located. -[[ -z ${_Dbg_cdir} ]] && typeset _Dbg_cdir=${_Dbg_source_file%/*} -[[ -z ${_Dbg_cdir} ]] && typeset _Dbg_cdir=$(pwd) +[[ -z ${_Dbg_cdir} ]] && typeset _Dbg_cdir="${_Dbg_source_file%/*}" +[[ -z ${_Dbg_cdir} ]] && typeset _Dbg_cdir="$(pwd)" # Either fill out or strip filename as determined by "basename_only" # and annotate settings diff --git a/lib/filecache.sh b/lib/filecache.sh index 5c99b04..bf9e557 100644 --- a/lib/filecache.sh +++ b/lib/filecache.sh @@ -139,14 +139,14 @@ function _Dbg_is_file { if [[ ${find_file:0:1} == '/' ]] ; then # Absolute file name - try_find_file=$(_Dbg_expand_filename "$find_file") + try_find_file="$(_Dbg_expand_filename "$find_file")" if [[ -n ${_Dbg_filenames[$try_find_file]} ]] ; then echo "$try_find_file" return 0 fi elif [[ ${find_file:0:1} == '.' ]] ; then # Relative file name - try_find_file=$(_Dbg_expand_filename "${_Dbg_init_cwd}/$find_file") + try_find_file="$(_Dbg_expand_filename "${_Dbg_init_cwd}/$find_file")" # FIXME: turn into common subroutine if [[ -n ${_Dbg_filenames[$try_find_file]} ]] ; then echo "$try_find_file" @@ -164,7 +164,7 @@ basename=$_Dbg_cdir elif [[ $basename == '\$cwd' ]] ; then basename=$(pwd) fi - try_find_file=$(_Dbg_expand_filename "$basename/$find_file") + try_find_file="$(_Dbg_expand_filename "$basename/$find_file")" if [[ -n ${_Dbg_filenames[$try_find_file]} ]] ; then echo "$try_find_file" return 0