Skip to content
Snippets Groups Projects

Add template to mktemp commands, for compatibility with earlier versions of MacOS.

Merged Alex McLean requested to merge yaxu/ghcup:patch-2 into master
2 unresolved threads

Merge request reports

Pipeline #12165 passed

Pipeline passed for 264d84be on yaxu:patch-2

Merged by Julian OspaldJulian Ospald 5 years ago (Nov 13, 2019 3:39am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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.

  • Please register or sign in to reply
  • Author Contributor

    Ah, I've barely done any shell programming before so don't know these idioms. But I didn't think I was making an api, just a function for use within the same script. As far as I can tell, this has the same behaviour as the previous version, in terms of tests and variables.

  • Author Contributor

    It would be good to have this resolved soon, I just ran a workshop and two people couldn't install ghcup due to this issue.

  • mentioned in issue #121 (closed)

  • I'm taking a look now

  • Julian Ospald mentioned in merge request !126 (merged)

    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 Ospald
  • merged

  • Author Contributor

    Thanks, that does look better

  • Contributor

    Hi, The current mktempdir function is not working on my OSX 10.10 Yosemite machine. I believe the .XXXX suffix is necessary on this platform. Not a very smart fix, but ghcup could just try the same mktemp command with the suffix if it fails without?

  • Contributor

    Ok, I found the culprit. Sorry to criticise, but this is a stupid mistake: the test against mydistro = "darwin" in mktempdir was always failing since mydistro was not set in that function. Great.

    I'll create a merge request ASAP. Don't make these kinds of mistakes please.

  • Contributor

    Here'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.

    !130 (merged)

  • Olius mentioned in merge request !130 (merged)

    mentioned in merge request !130 (merged)

  • mentioned in issue #130 (closed)

  • Please register or sign in to reply
    Loading