haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.62k stars 697 forks source link

Figure out why `MAX_PATH` is still a problem in Cabal #10191

Closed jasagredo closed 1 month ago

jasagredo commented 4 months ago

Base should be fixed once WinIO was merged, but there are still tests which even in newer GHCs still fail with MAX_PATH issues:

 C:\Users\runneradmin\AppData\Local\Temp\cabal-testsuite-26120\cabal-external.dist\work\.\dist\build\x86_64-windows\ghc-9.10.1\indef-0.1.0.0\indef-0.1.0.0-inplace+3YxWX6XJM8s5QouYtC2nTB\build\indef-0.1.0.0-inplace+3YxWX6XJM8s5QouYtC2nTB\autogen\Data\: openBinaryTempFileWithDefaultPermissions: invalid argument (CallStack (from HasCallStack):

  withMetadata, called at src\Distribution\Simple\Utils.hs:459:7 in Cabal-3.13.0.0-inplace:Distribution.Simple.Utils

Mistuke mentioned that Cabal uses its own logic for temp files, but this one looks like it uses the base one. This is worth investigating in any case, because Backpack results in very long paths always...

System information

jasagredo commented 3 months ago

Tests that are currently marked as failing because of this:

jasagredo commented 1 month ago

Cabal uses temporary files for writing files atomically. It then renames the file to the right name after writing it. However this cannot deal with long paths on Windows.

See how GetTempFileNameW specifies:

The string cannot be longer than MAX_PATH–14 characters or GetTempFileName will fail.

And actually there is a TODO in Win32Utils.c in GHC:

https://gitlab.haskell.org/ghc/ghc/-/blob/3939a8bf93e27d8151aa1d92bf3ce10bbbc96a72/libraries/ghc-internal/cbits/Win32Utils.c#L259

So my suggestion and the PR I'm preparing is to create temp files in the global temp directory instead of in the final destination. This is somewhat of a breaking change, but I don't think it will be too noticeable.

However this is kind of blocked on https://github.com/haskell/directory/issues/189 to make this transparent for cabal, as otherwise users with multiple drives might have a hard time.