diff options
author | Bryan Drewery <bryan@shatow.net> | 2021-11-17 06:37:08 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2021-11-18 16:13:45 +0300 |
commit | cefb5070136ccb7de0f9c65becaafe18763d3bed (patch) | |
tree | 88bd53de13bbec3626ad26b034c5719c78937755 /src | |
parent | 80ec59d8e523fc116f80a8555a5d38bb60f09510 (diff) |
mapfile_write (from stdin): Fix writing newline when none is read
Diffstat (limited to 'src')
-rw-r--r-- | src/poudriere-sh/mapfile.c | 6 | ||||
-rw-r--r-- | src/share/poudriere/include/util.sh | 8 |
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 |