Skip to content

Commit 63c3ad7

Browse files
authored
Merge pull request #6258 from commercialhaskell/fix6257
Fix #6257 Allow MSYS2 to install on different drive to sys temp dir's
2 parents 50d9c5a + c477a75 commit 63c3ad7

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Bug fixes:
2424

2525
* Restore message suffix `due to warnings` with `dump-logs: warning` (broken
2626
with Stack 2.11.1).
27+
* On Windows, the `local-programs-path` directory can now be on a different
28+
drive to the system temporary directory and MSYS2 will still be installed.
2729

2830
## v2.13.0.1 (release candidate) - 2023-09-16
2931

src/Stack/Setup.hs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import Data.Conduit.Process.Typed ( createSource )
4343
import Data.Conduit.Zlib ( ungzip )
4444
import Data.List.Split ( splitOn )
4545
import qualified Data.Map as Map
46+
import Data.Maybe ( fromJust )
4647
import qualified Data.Set as Set
4748
import qualified Data.Text as T
4849
import qualified Data.Text.Lazy as TL
@@ -65,16 +66,17 @@ import Network.HTTP.StackClient
6566
)
6667
import Network.HTTP.Simple ( getResponseHeader )
6768
import Path
68-
( (</>), addExtension, filename, parent, parseAbsDir
69-
, parseAbsFile, parseRelDir, parseRelFile, toFilePath
69+
( (</>), addExtension, filename, fromAbsDir, parent
70+
, parseAbsDir, parseAbsFile, parseRelDir, parseRelFile
71+
, toFilePath
7072
)
7173
import Path.CheckInstall ( warnInstallSearchPathIssues )
7274
import Path.Extended ( fileExtension )
7375
import Path.Extra ( toFilePathNoTrailingSep )
7476
import Path.IO
7577
( canonicalizePath, doesFileExist, ensureDir, executable
7678
, getPermissions, ignoringAbsence, listDir, removeDirRecur
77-
, renameDir, renameFile, resolveFile'
79+
, renameDir, renameFile, resolveFile', withTempDir
7880
)
7981
import RIO.List
8082
( headMaybe, intercalate, intersperse, isPrefixOf
@@ -165,7 +167,7 @@ import Stack.Types.VersionedDownloadInfo
165167
import qualified System.Directory as D
166168
import System.Environment ( getExecutablePath, lookupEnv )
167169
import System.IO.Error ( isPermissionError )
168-
import System.FilePath ( searchPathSeparator )
170+
import System.FilePath ( searchPathSeparator, takeDrive )
169171
import qualified System.FilePath as FP
170172
import System.Permissions ( setFileExecutable )
171173
import System.Uname ( getRelease )
@@ -2344,18 +2346,23 @@ withUnpackedTarball7z name si archiveFile archiveType destDir = do
23442346
-- We use a short name for the temporary directory to reduce the risk of a
23452347
-- filepath length of more than 260 characters, which can be problematic for
23462348
-- 7-Zip even if Long Filepaths are enabled on Windows.
2347-
let tmpName = "tmp"
2349+
let tmpName = "stack-tmp"
2350+
destDrive = fromJust $ parseAbsDir $ takeDrive $ fromAbsDir destDir
23482351
ensureDir (parent destDir)
23492352
withRunInIO $ \run ->
2350-
-- We use the system temporary directory to reduce the risk of a filepath
2351-
-- length of more than 260 characters, which can be problematic for
2352-
-- 7-Zip even if Long Filepaths are enabled on Windows.
2353-
withSystemTempDir tmpName $ \tmpDir ->
2353+
-- We use a temporary directory in the same drive as that of 'destDir' to
2354+
-- reduce the risk of a filepath length of more than 260 characters, which can
2355+
-- be problematic for 7-Zip even if Long Filepaths are enabled on Windows. We
2356+
-- do not use the system temporary directory as it may be on a different
2357+
-- drive.
2358+
withTempDir destDrive tmpName $ \tmpDir ->
23542359
run $ do
23552360
liftIO $ ignoringAbsence (removeDirRecur destDir)
23562361
run7z tmpDir archiveFile
23572362
run7z tmpDir (tmpDir </> tarFile)
23582363
absSrcDir <- expectSingleUnpackedDir archiveFile tmpDir
2364+
-- On Windows, 'renameDir' does not work across drives. However, we have
2365+
-- ensured that 'tmpDir' has the same drive as 'destDir'.
23592366
renameDir absSrcDir destDir
23602367

23612368
expectSingleUnpackedDir ::

stack.cabal

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.0
22

3-
-- This file has been generated from package.yaml by hpack version 0.35.5.
3+
-- This file has been generated from package.yaml by hpack version 0.36.0.
44
--
55
-- see: https://github.com/sol/hpack
66

@@ -40,10 +40,8 @@ extra-source-files:
4040
doc/clean_command.md
4141
doc/config_command.md
4242
doc/CONTRIBUTING.md
43-
doc/coverage.md
4443
doc/custom_snapshot.md
4544
doc/debugging.md
46-
doc/dependency_visualization.md
4745
doc/dev_containers.md
4846
doc/developing_on_windows.md
4947
doc/docker_command.md

0 commit comments

Comments
 (0)