Add template to mktemp commands, for compatibility with earlier versions of MacOS.
Merge request reports
Activity
Did you check whether this is portable across all platforms? mktemp (1) is not specified by posix: https://stackoverflow.com/questions/2792675/how-portable-is-mktemp1
No, but I can say that it worked for that MacOS 10.9 user, and it works for me under Linux mint. I got the fix from the yarn installer: https://github.com/yarnpkg/yarn/issues/1984 So it seems that specifying the template is generally supported, and in the case of earlier MacOS versions, required.
Nope: https://gitlab.haskell.org/haskell/ghcup/blob/master/.download-urls#L74
Also, ghcup tries to be POSIX compatible, as described in the readme. Whenever we can't achieve it, because POSIX is underspecified, we try to be as portable as possible.
The -t parameter seems to do the same thing under FreeBSD https://www.freebsd.org/cgi/man.cgi?query=mktemp&sektion=1 Otherwise, the parameter could be added if Darwin is detected
This FreeBSD version also seems to require -t: https://www.freebsd.org/cgi/man.cgi?query=mktemp
The portability link you posted suggested Darwin's version is based on FreeBSD
It might in the end be safest to specify it for everything, if we can verify it works under the supported platforms.
The linux manpage says this of -t:
-t interpret TEMPLATE as a single file name component, relative to a directory: $TMPDIR, if set; else the directory specified via -p; else /tmp [deprecated]
That deprecated notice worries me, but I don't know whether the parameter is deprecated, or the defaulting to
/tmp
.. That is, I don't know whether the -t is going away, or is becoming mandatory!Sorry for the multiple posts. After more manpage reading my conclusion is that:
- Some *BSD derived platforms , including MacOS 10.9 require a template to be set
- The -t parameter seems to be a cross-platform way to get the temp file / directory to be created under $TMPDIR or /tmp, which we probably want
So FWIW my vote is to merge this as-is, but if there's someone who can test it under FreeBSD that would be better.
Edited by Alex McLeanI've booted a FreeBSD 12 VM
mktemp -d -t ghcup.XXXXXXXX
works, but creates a folder like/tmp/ghcup.XXXXXXXX.u2Uq32ue
. A little bit messy.mktemp -d
works too, creates a folder like/tmp/tmp.v9ACTpFVjm
, seems to have the same behaviour as linuxIs it worth complicating the code to avoid a messily named temporary folder?
Edited by Alex McLeanadded 1 commit
- 264d84be - provide temporary directory name prefix only for Darwin
1020 1020 edo ${DOWNLOADER} ${DOWNLOADER_STDOUT_OPTS} "$1" 2> /dev/null 1021 1021 } 1022 1022 1023 # @FUNCTION: mktempdir 1024 # @DESCRIPTION: 1025 # Makes a temporary directory, placing the path in $tmp_dir. 1026 mktempdir() { 1027 if test "${mydistro}" = "darwin"; then 1028 debug_message "mktemp -d -t ghcup" 1029 tmp_dir=$(mktemp -d -t ghcup) 1030 else 1031 debug_message "mktemp -d" 1032 tmp_dir=$(mktemp -d) 1033 fi 1034 [ -z "${tmp_dir}" ] && die "Failed to create temporary directory" Now that I think about it, check not just if the variable is set, but also if the directory exists!
https://pubs.opengroup.org/onlinepubs/009695399/utilities/test.html
Also, we are basically creating a global variable and don't know when a caller reads it. So the caller has to unset it as well. This is problematic API.
I suggest to remove the error checks and just have a simple if else for the mktemp call, without setting any variable and without erroring out. Then the caller Has full control.
mentioned in issue #121 (closed)
mentioned in merge request !126 (merged)
Since I don't like the implicit setting of tmp_dir in mktempdir I made an alternative version: !126 (merged)
Edited by Julian OspaldHere's the merge request. I've never been able to get ghcup to run on my machine, and this seems to have been the reason all along.
mentioned in merge request !130 (merged)
mentioned in issue #130 (closed)