Skip to content

Commit 96c39fd

Browse files
committed
replace readlink calls
1 parent 26fbba0 commit 96c39fd

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

impd

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,18 @@ fetch_episode_number() {
252252
} | tail -1
253253
}
254254

255+
canonicalize() {
256+
# alternative to calling 'readlink -f' but using only shell built-ins.
257+
if [[ $1 == /* ]]; then
258+
echo "$1"
259+
else
260+
echo "$PWD/$1"
261+
fi
262+
}
263+
255264
extract_subtitles() {
256-
local input="${1:?Input path not set.}"
257-
local output="${2:?Output path not set.}"
258-
local -r input=$( readlink -f -- "$input" )
259-
local -r output=$( readlink -f -- "$output" )
265+
local -r input=$( canonicalize "${1:?Input path not set.}" )
266+
local -r output=$( canonicalize "${2:?Output path not set.}" )
260267
local -r track_num=${3:-$( best_track s "$input" )}
261268

262269
echo "Extracting track #${track_num:-auto} (subtitles) from ${input##*/}..."
@@ -305,8 +312,8 @@ check_output() {
305312
}
306313

307314
extract_audio() {
308-
local -r input=$( readlink -f -- "${1:?Input file not set.}" )
309-
local -r output=$( readlink -f -- "${2:-$immersionpod_dir/$current/$( make_output_basename "$input" ).ogg}" )
315+
local -r input=$( canonicalize "${1:?Input file not set.}" )
316+
local -r output=$( canonicalize "${2:-$immersionpod_dir/$current/$( make_output_basename "$input" ).ogg}" )
310317
local -r track_num=${3:-$( best_track a "$input" )}
311318

312319
if ! check_output; then
@@ -405,8 +412,7 @@ find_external_subtitles() {
405412
return 1
406413
fi
407414

408-
local video=${1:?Video path not set.}
409-
video=$( readlink -f -- "$video" ) # convert to full path
415+
local video=$( canonicalize "${1:?Video path not set.}" ) # convert to full path
410416
local -r dir=${video%/*} # remove last component
411417
video=${video##*/} # basename
412418
local -r video=${video%.*} # remove extension
@@ -618,19 +624,19 @@ concat_audio() {
618624
}
619625

620626
make_condensed() {
621-
local -r video=$( readlink -f -- "${1:?}" )
627+
local -r video=$( canonicalize "${1:?Video path not set.}" ) # convert to full path
622628
local -r base=$( make_output_basename "$video" )
623629

624630
local -r job_dir=$(mktemp -d --tmpdir="$tmp_dir" -t "$base.job-XXXX")
625631

626632
local -r temp_audio=$job_dir/$base.ogg
627-
local -r output=$( readlink -f -- "${2:-$immersionpod_dir/$current/$base.ogg}" )
633+
local -r output=$( canonicalize "${2:-$immersionpod_dir/$current/$base.ogg}" )
628634

629635
local -r chunks_dir=$(mktemp -d --tmpdir="$job_dir" -t "chunks-XXXX")
630636
local -r chunks_file=$job_dir/chunks.list
631637

632638
local -r subs_out=$job_dir/$base.srt
633-
local -r subs_external=$( readlink -f -- "${3:-$( find_external_subtitles "$video" )}" )
639+
local -r subs_external=$( canonicalize "${3:-$( find_external_subtitles "$video" )}" )
634640

635641
local -r subs_track_num=${4-}
636642
local -r audio_track_num=${5-}
@@ -731,7 +737,7 @@ notify_send() {
731737
}
732738

733739
add_file() {
734-
local -r source_file=$( readlink -f -- "${1:?Source file not set.}" )
740+
local -r source_file=$( canonicalize "${1:?Source file not set.}" )
735741

736742
if [[ -f $source_file ]]; then
737743
if [[ -z ${global_no_condense-} ]]; then

0 commit comments

Comments
 (0)