Stack tries to create temporary folder in drive root?

This is a very newbie question, so, my apologies, but I am at my wit’s end trying to figure this out.

I’m using stack version 3.1.1 for windows and, try as I might, I cannot avoid getting the following error:
Already downloaded msys2-20240727.
Already downloaded 7z.dll.
Already downloaded 7z.exe.
C:\stack-tmp-ee8f5b455efe402d: CreateDirectory “\\?\C:\stack-tmp-ee8f5b455efe402d”: permission denied (Access is denied.)

I believe I’ve set appropriate values for TMP which my reading said was where the temp directory should be. So, if anyone has any help for me, I’d be grateful.

Is there a way to get stack to print out the environment variables it’s using?
Am I setting the wrong environment variables.

Thanks in advance

2 Likes

On Stack’s environment, command stack config env. See:

It looks like Stack is trying to create a temporary directory in a location where it does not have permission. I’ll check Stack’s code, but I am surprised that it is trying to do that in the root of the C:\ drive.

1 Like

Thank you; that would be great. I’m not familiar enough with the layout of Stack to even know where to look in the code!

Having looked at Stack’s code, Stack should be creating that temporary directory in ~the configured ‘local programs’ directory.~ [EDIT1: That’s not correct; see below.] That is configured in a Stack configuration file using the local-programs-path key: Non-project specific configuration - The Haskell Tool Stack

Command stack path --programs to see what Stack understands to be the configured location. See: path - The Haskell Tool Stack

EDIT1: Strike that. Having looked at Stack’s verbose output, it seems to be doing something different … update to follow.

EDIT2: Correction: Stack.Setup.withUnpackedTarball7z has (extract):

  withRunInIO $ \run ->
  -- We use a temporary directory in the same drive as that of 'destDir' to
  -- reduce the risk of a filepath length of more than 260 characters, which can
  -- be problematic for 7-Zip even if Long Filepaths are enabled on Windows. We
  -- do not use the system temporary directory as it may be on a different
  -- drive.
    withTempDir destDrive tmpName $ \tmpDir ->
      run $ do
        liftIO $ ignoringAbsence (removeDirRecur destDir)
        run7z tmpDir archiveFile
        ...

Stack is trying to create a temporary directory in C:\ because of an understood limitation with 7-Zip.

EDIT3: That 7-Zip limitation may be ancient history looking at 9.32 alpha of 2013-12-01: https://www.7-zip.org/history.txt

EDIT4: Since September 2022, new installations of Stack will have used 7-Zip 22.01.

EDIT5: I don’t know if it is yet safe (in mid-2025) to assume that Stack (and, consequently, 7-Zip) is being used on a Windows system with long file paths enabled.

1 Like

I really appreciate the help - I’ll look into this

programs is set, as I planned to C:\SEI\Tools\bin\x86_64-windows

To document this, I have added something to the Windows-specific part of: setup - The Haskell Tool Stack

EDIT1: However, Stack likely needs to be cleverer than it currently is being. I’ll raise an issue and look at a fix.

EDIT2: I think this is now fixed in the master branch version of Stack (if not using GHCup to manage versions of Stack: stack upgrade --source-only --git.) I would be good if somebody who does not have permission to create a folder in the root of C:\ could test it is a fix. There is a Windows binary distribution here: https://github.com/commercialhaskell/stack/actions/runs/15221475103/artifacts/3189164997 or https://github.com/commercialhaskell/stack/actions/runs/15230682209/artifacts/3191270032

1 Like

The added documentation is useful but not helpful. You’re correct that I typically run as a regular user and not as administrator - it’s a safety policy that makes a lot of sense to me.

Is there a way to enable long file paths? If not, is my only solution to run as admin?

See my edited post above. I think this is now fixed in the master branch version of Stack, and it would be good if you could test that.

So this is very naive - are there instructions on how to build stack? In the past I have just downloaded a Windows binary! Or is there a link to a new binary using your modification?

Thanks

I’ve added links above to binary distributions (in an archive file).

Each time Stack’s integration-tests GitHub workflow completes, as part of the CI at its GitHub repository, it creates binary distributions as an artefact.

Sorry for being slow to follow up. I tried the stack upgrade command both as administrator and as a regular user, in both cases I ended up with “git: readCreateProcess: does not exist (No such file or directory)”

Both links lead me to the git version of 404 Not found otherwise I’d download and install a version

I don’t know why the URL’s do not work for you - can I check that you are logged into GitHub when you access them?

Thanks; I wasn’t signed in. I have downloaded the updated version and will test it out and let you know

Thank you, thank you, thank you. I tried the first link: the 64-bit version and everything works as expected.

The fix is perfect and has enabled me to make progress on my original task!

I aim to release new versions of Stack around calendar quarter ends, unless nothing much has happened. So, this should be available in a released version of Stack in about a month’s time.