Skip to content

Commit

Permalink
Merge pull request #223 from tegonal/bugfix/withCustomOutputInput-var…
Browse files Browse the repository at this point in the history
…iables-names-could-clash

prefix variable names in withCustomInputOutput to avoid clashes
  • Loading branch information
robstoll authored Dec 6, 2024
2 parents 6e381b2 + 1d04918 commit b986fbc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ declare -fx findScripts
function specialBeforePr(){
beforePr && echo "imagine some additional work"
}
# make the function visible to release-files.sh / not necessary if you sourcerepare-files-next-dev-cycle.sh, see further below
# make the function visible to release-files.sh / not necessary if you source prepare-files-next-dev-cycle.sh
# see further below
declare -fx specialBeforePr
# releases version v0.1.0 using the key 0x945FE615904E5C85 for signing and
Expand Down
3 changes: 2 additions & 1 deletion src/releasing/release-files.doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ declare -fx findScripts
function specialBeforePr(){
beforePr && echo "imagine some additional work"
}
# make the function visible to release-files.sh / not necessary if you sourcerepare-files-next-dev-cycle.sh, see further below
# make the function visible to release-files.sh / not necessary if you source prepare-files-next-dev-cycle.sh
# see further below
declare -fx specialBeforePr

# releases version v0.1.0 using the key 0x945FE615904E5C85 for signing and
Expand Down
3 changes: 2 additions & 1 deletion src/releasing/release-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
# function specialBeforePr(){
# beforePr && echo "imagine some additional work"
# }
# # make the function visible to release-files.sh / not necessary if you sourcerepare-files-next-dev-cycle.sh, see further below
# # make the function visible to release-files.sh / not necessary if you source prepare-files-next-dev-cycle.sh
# # see further below
# declare -fx specialBeforePr
#
# # releases version v0.1.0 using the key 0x945FE615904E5C85 for signing and
Expand Down
27 changes: 14 additions & 13 deletions src/utility/io.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Version: v4.2.0-SNAPSHOT
####### Description #############
#
# utility function dealing with Input/Ouput
# utility function dealing with Input/Output
#
####### Usage ###################
#
Expand Down Expand Up @@ -51,24 +51,25 @@ fi
sourceOnce "$dir_of_tegonal_scripts/utility/checks.sh"

function withCustomOutputInput() {
local outputNr=$1
local inputNr=$2
local fun=$3
# prefix variables as the callback function might use variables from an outer scope and we would shadow those
local withCustomOutputInput_outputNr=$1
local withCustomOutputInput_inputNr=$2
local withCustomOutputInput_fun=$3
shift 3 || traceAndDie "could not shift by 3"

exitIfArgIsNotFunction "$fun" 3
exitIfArgIsNotFunction "$withCustomOutputInput_fun" 3

local tmpFile
tmpFile=$(mktemp /tmp/tegonal-scripts-io.XXXXXXXXX)
eval "exec ${outputNr}>\"$tmpFile\"" || traceAndDie "could not create output file descriptor %s" "$outputNr"
eval "exec ${inputNr}<\"$tmpFile\"" || traceAndDie "could not create input file descriptor %s" "$inputNr"
local withCustomOutputInput_tmpFile
withCustomOutputInput_tmpFile=$(mktemp /tmp/tegonal-scripts-io.XXXXXXXXX)
eval "exec ${withCustomOutputInput_outputNr}>\"$withCustomOutputInput_tmpFile\"" || traceAndDie "could not create output file descriptor %s" "$withCustomOutputInput_outputNr"
eval "exec ${withCustomOutputInput_inputNr}<\"$withCustomOutputInput_tmpFile\"" || traceAndDie "could not create input file descriptor %s" "$withCustomOutputInput_inputNr"
# don't fail if we cannot delete the tmp file, if this should happened, then the system should clean-up the file when the process ends
rm "$tmpFile" || true
rm "$withCustomOutputInput_tmpFile" || true

$fun "$@"
$withCustomOutputInput_fun "$@"

eval "exec ${outputNr}>&-"
eval "exec ${inputNr}<&-"
eval "exec ${withCustomOutputInput_outputNr}>&-"
eval "exec ${withCustomOutputInput_inputNr}<&-"
}

function deleteDirChmod777() {
Expand Down

0 comments on commit b986fbc

Please sign in to comment.