diff options
author | Bryan Drewery <bryan@shatow.net> | 2020-05-09 00:30:52 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2021-04-06 03:08:49 +0300 |
commit | b37898866d596fecdb3ce53fd79dd2ec5aa3434a (patch) | |
tree | 1e0bfe73070b345fba44ae748216cfb3b15619ce | |
parent | 8e6946be35f969ca8d1607de8551acc8609db801 (diff) |
mapfile: Assume read -r behavior by default
-rw-r--r-- | src/poudriere-sh/mapfile.c | 1 | ||||
-rw-r--r-- | src/share/poudriere/include/util.sh | 8 | ||||
-rw-r--r-- | test/mapfile.sh | 14 |
3 files changed, 12 insertions, 11 deletions
diff --git a/src/poudriere-sh/mapfile.c b/src/poudriere-sh/mapfile.c index 416d81f7..7427b202 100644 --- a/src/poudriere-sh/mapfile.c +++ b/src/poudriere-sh/mapfile.c @@ -63,6 +63,7 @@ struct mapped_data { static struct mapped_data *mapped_files[MAX_FILES] = {0}; /* Avoid remallocing every call */ static char *line = NULL; +/* This should be blksize for the file type. See readcmd builtin */ static size_t linecap = BUFSIZ; #include "bltin/bltin.h" diff --git a/src/share/poudriere/include/util.sh b/src/share/poudriere/include/util.sh index afff4e72..12309ba9 100644 --- a/src/share/poudriere/include/util.sh +++ b/src/share/poudriere/include/util.sh @@ -503,7 +503,7 @@ read_pipe() { # since opening the pipe blocks and may be interrupted. resread=0 resopen=0 - { { read "$@" || resread=$?; } < "${fifo}" || resopen=$?; } \ + { { read -r "$@" || resread=$?; } < "${fifo}" || resopen=$?; } \ 2>/dev/null msg_dev "read_pipe ${fifo}: resread=${resread} resopen=${resopen}" # First check the open errors @@ -593,7 +593,7 @@ mapfile_read() { read_blocking_line "$@" < "${handle}" elif [ "${handle}" = "/dev/fd/0" ]; then # mapfile_read_loop_redir pipe - read "$@" + read -r "$@" else return 1 fi @@ -637,7 +637,7 @@ mapfile_read_loop() { err 1 "mapfile_read_loop only supports 1 file at a time without builtin" fi ret=0 - read "$@" <&8 || ret=$? + read -r "$@" <&8 || ret=$? if [ ${ret} -ne 0 ]; then exec 8>&- unset _mapfile_read_loop @@ -646,7 +646,7 @@ mapfile_read_loop() { } mapfile_read_loop_redir() { - read "$@" + read -r "$@" } else diff --git a/test/mapfile.sh b/test/mapfile.sh index 449aaff3..ec5e868b 100644 --- a/test/mapfile.sh +++ b/test/mapfile.sh @@ -35,8 +35,8 @@ writer() { n=0 until [ $n -eq ${LINES} ]; do case ${type} in - pipe) echo "${n}" ;; - mapfile) mapfile_write "${out}" "${n}" ;; + pipe) echo "${n}\\" ;; + mapfile) mapfile_write "${out}" "${n}\\" ;; esac n=$((n + 1)) done @@ -76,11 +76,11 @@ if mapfile_builtin; then until [ $n -eq ${LINES} ]; do mapfile_read "${handle1}" line assert 0 $? "mapfile_read handle1 should succeed line $n" - assert "$n" "$line" "mapfile_read handle1 should match line $n" + assert "${n}\\" "$line" "mapfile_read handle1 should match line $n" mapfile_read "${handle2}" line assert 0 $? "mapfile_read handle2 should succeed line $n" - assert "$n" "$line" "mapfile_read handle2 should match line $n" + assert "${n}\\" "$line" "mapfile_read handle2 should match line $n" n=$((n + 1)) done @@ -162,13 +162,13 @@ if mapfile_builtin; then assert " test 1 2 3 " "${line}" "mapfile_read IFS= should match line 2" assert "" "${extra}" "mapfile_read IFS= should match extra 2" - # IFS mode - mapfile_write "${file_out}" " test 1 2 3 " + # IFS mode and default read -r behavior + mapfile_write "${file_out}" " t\\est 1 2 3 " assert 0 $? "mapfile_write to standard file_out should pass" extra="blah" mapfile_read "${file_in}" line extra assert 0 $? "mapfile_read from standard file_in to 2.1 var should pass" - assert "test" "${line}" "mapfile_read should match line 2.1" + assert "t\\est" "${line}" "mapfile_read should match line 2.1" assert "1 2 3" "${extra}" "mapfile_read should match extra 2.1" mapfile_write "${file_out}" "test 1 2 3" |