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>2021-11-17 06:37:08 +0300
committerBryan Drewery <bryan@shatow.net>2021-11-18 16:13:45 +0300
commitcefb5070136ccb7de0f9c65becaafe18763d3bed (patch)
tree88bd53de13bbec3626ad26b034c5719c78937755 /src
parent80ec59d8e523fc116f80a8555a5d38bb60f09510 (diff)
mapfile_write (from stdin): Fix writing newline when none is read
Diffstat (limited to 'src')
-rw-r--r--src/poudriere-sh/mapfile.c6
-rw-r--r--src/share/poudriere/include/util.sh8
2 files changed, 10 insertions, 4 deletions
diff --git a/src/poudriere-sh/mapfile.c b/src/poudriere-sh/mapfile.c
index 33cd358a..fe14009d 100644
--- a/src/poudriere-sh/mapfile.c
+++ b/src/poudriere-sh/mapfile.c
@@ -543,8 +543,12 @@ mapfile_writecmd(int argc, char **argv)
* XXX: Using shell mapfile_cat until some changes from
* copool branch make it in to avoid massive conflicts
*/
- const char *cmd = "__mapfile_write_cat=$(mapfile_cat)";
+ /* Avoid adding our own newline by keeping any read. */
+ const char *cmd =
+ "__mapfile_write_cat=\"$(mapfile_cat; echo .)\";"
+ "__mapfile_write_cat=\"${__mapfile_write_cat%.}\"";
+ nflag = 1;
evalstring(cmd, 0);
if (exitstatus != 0) {
ret = exitstatus;
diff --git a/src/share/poudriere/include/util.sh b/src/share/poudriere/include/util.sh
index cf5e2d43..8b039948 100644
--- a/src/share/poudriere/include/util.sh
+++ b/src/share/poudriere/include/util.sh
@@ -701,12 +701,14 @@ _mapfile_write_from_stdin() {
[ $# -eq 1 ] || eargs _mapfile_write_from_stdin handle
local data
- data="$(cat)"
- _mapfile_write "$@" "${data}"
+ # . is to preserve newline
+ data="$(cat; echo .)"
+ data="${data%.}"
+ _mapfile_write "$@" -n "${data}"
}
_mapfile_write() {
- [ $# -eq 2 ] || eargs mapfile_write handle data
+ [ $# -ge 2 ] || eargs mapfile_write handle [-n] data
local handle="$1"
shift
local fd