From 3e3a42c127a845cfa6d7822ac938200b2f567547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Rolim?= Date: Fri, 13 Nov 2020 00:14:18 -0300 Subject: [PATCH] build_tools/fish_xgettext.fish: use temporary directory. Instead of using /tmp/fish as a temporary directory for this operation, which could lead to clobbering user files, use mktemp to create an actual temporary directory. --- build_tools/fish_xgettext.fish | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/build_tools/fish_xgettext.fish b/build_tools/fish_xgettext.fish index 9fdb1609b..6977d7c3f 100755 --- a/build_tools/fish_xgettext.fish +++ b/build_tools/fish_xgettext.fish @@ -22,34 +22,39 @@ set -l implicit_regex '(?:^| +)(?:complete|function).*? (?:-d|--description) (([ # than messages which should be implicitly translated. set -l explicit_regex '.*\( *_ (([\'"]).+?(?/tmp/fish/explicit/$f.tmp 2>/dev/null + string replace --filter --regex $explicit_regex 'echo $1' <$f | fish >$tmpdir/explicit/$f.tmp 2>/dev/null while read description echo 'N_ "'(string replace --all '"' '\\"' -- $description)'"' - end /tmp/fish/explicit/$f - rm /tmp/fish/explicit/$f.tmp + end <$tmpdir/explicit/$f.tmp >$tmpdir/explicit/$f + rm $tmpdir/explicit/$f.tmp # Handle `complete` / `function` description messages. The `| fish` is subtle. It basically # avoids the need to use `source` with a command substitution that could affect the current # shell. - string replace --filter --regex $implicit_regex 'echo $1' <$f | fish >/tmp/fish/implicit/$f.tmp 2>/dev/null + string replace --filter --regex $implicit_regex 'echo $1' <$f | fish >$tmpdir/implicit/$f.tmp 2>/dev/null while read description # We don't use `string escape` as shown in the next comment because it produces output that # is not parsed correctly by xgettext. Instead just escape double-quotes and quote the # resulting string. echo 'N_ "'(string replace --all '"' '\\"' -- $description)'"' - end /tmp/fish/implicit/$f - rm /tmp/fish/implicit/$f.tmp + end <$tmpdir/implicit/$f.tmp >$tmpdir/implicit/$f + rm $tmpdir/implicit/$f.tmp end -xgettext -j -k -kN_ -LShell --from-code=UTF-8 -cDescription --no-wrap -o messages.pot /tmp/fish/explicit/share/*/*.fish -xgettext -j -k -kN_ -LShell --from-code=UTF-8 -cDescription --no-wrap -o messages.pot /tmp/fish/implicit/share/*/*.fish +xgettext -j -k -kN_ -LShell --from-code=UTF-8 -cDescription --no-wrap -o messages.pot $tmpdir/explicit/share/*/*.fish +xgettext -j -k -kN_ -LShell --from-code=UTF-8 -cDescription --no-wrap -o messages.pot $tmpdir/implicit/share/*/*.fish -rm -r /tmp/fish +rm -r $tmpdir