From e2a8b78d9a6ad9aa8352ba795b1d8c00f70efe96 Mon Sep 17 00:00:00 2001 From: Luiz Angelo Daros de Luca Date: Thu, 30 May 2019 18:53:22 -0300 Subject: [PATCH] workaround win32 mktemp bug win32 mktemp shipped by easyrsa does not work. It returns unmodified template as the "temporary file". This results in file conflicts when two temporary files are in use. However win32 mktemp -d does work as expected. So, we can use mktemp -du to generate a correct temporary file name. Signed-off-by: Luiz Angelo Daros de Luca --- easyrsa3/easyrsa | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/easyrsa3/easyrsa b/easyrsa3/easyrsa index 0c569e8..10219d6 100755 --- a/easyrsa3/easyrsa +++ b/easyrsa3/easyrsa @@ -311,7 +311,18 @@ easyrsa_mktemp() { [ -n "$EASYRSA_TEMP_DIR_session" ] || die "EASYRSA_TEMP_DIR_session not initialized!" [ -d "$EASYRSA_TEMP_DIR_session" ] || mkdir -p "$EASYRSA_TEMP_DIR_session" || die "Could not create temporary directory '$EASYRSA_TEMP_DIR_session'. Permission or concurrency problem?" - mktemp "$EASYRSA_TEMP_DIR_session/tmp.XXXXXX" + [ -d "$EASYRSA_TEMP_DIR_session" ] || die "Temporary directory '$EASYRSA_TEMP_DIR_session' does not exist" + + template="$EASYRSA_TEMP_DIR_session/tmp.XXXXXX" + tempfile=$(mktemp "$template") || return + + # win32 mktemp shipped by easyrsa returns template as file! + if [ "$template" = "$tempfile" ]; then + # but win32 mktemp -d does work + tempfile=$(mktemp -du "$tempfile") || return + printf "" > "$tempfile" || return + fi + echo "$tempfile" } # => easyrsa_mktemp # remove temp files and do terminal cleanups