Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/freebsd/poudriere.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBryan Drewery <bryan@shatow.net>2022-11-10 01:21:36 +0300
committerBryan Drewery <bryan@shatow.net>2022-11-10 02:06:20 +0300
commitbac8a649e2717554700b7e04f8b226db41d883dc (patch)
treef8b611661b8b5388deb23a0ec8ec2a360d7d2248 /src
parentb6a430f0b30e6d8ffc5151951b41430870a9bfba (diff)
mapfile sh: mapfile open for read should fail on missing file
Diffstat (limited to 'src')
-rw-r--r--src/share/poudriere/include/util.sh28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/share/poudriere/include/util.sh b/src/share/poudriere/include/util.sh
index 5d08f1c4..8debed3c 100644
--- a/src/share/poudriere/include/util.sh
+++ b/src/share/poudriere/include/util.sh
@@ -678,8 +678,20 @@ mapfile() {
[ $# -eq 2 -o $# -eq 3 ] || eargs mapfile handle_name file modes
local handle_name="$1"
local _file="$2"
- local mypid _hkey
+ local _modes="$3"
+ local mypid _hkey ret
+
+ case " ${_modes} " in
+ *r*w*|*w*r*) ;;
+ *w*|*a*) ;;
+ *r*)
+ if [ ! -r "${_file}" ]; then
+ return 1
+ fi
+ ;;
+ esac
+ ret=0
mypid=$(getpid)
case "${_file}" in
-|/dev/stdin) _file="/dev/fd/0" ;;
@@ -716,9 +728,21 @@ mapfile() {
hash_set mapfile_fd "${_mapfile_handle}" "${_file#/dev/fd/}"
;;
*)
- exec 8<> "${_file}" ;;
+ case " ${_modes} " in
+ *r*w*|*w*r*)
+ exec 8<> "${_file}" || ret="$?"
+ ;;
+ *r*)
+ exec 8< "${_file}" || ret="$?"
+ ;;
+ *w*|*a*)
+ exec 8> "${_file}" || ret="$?"
+ ;;
+ esac
+ ;;
esac
hash_set mapfile_file "${_mapfile_handle}" "${_file}"
+ return "${ret}"
}
mapfile_read() {