Skip to content

Commit

Permalink
Merge pull request #6258 from commercialhaskell/fix6257
Browse files Browse the repository at this point in the history
Fix #6257 Allow MSYS2 to install on different drive to sys temp dir's
  • Loading branch information
mpilgrem authored Sep 27, 2023
2 parents 50d9c5a + c477a75 commit 63c3ad7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Bug fixes:

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

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

Expand Down
25 changes: 16 additions & 9 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Data.Conduit.Process.Typed ( createSource )
import Data.Conduit.Zlib ( ungzip )
import Data.List.Split ( splitOn )
import qualified Data.Map as Map
import Data.Maybe ( fromJust )
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
Expand All @@ -65,16 +66,17 @@ import Network.HTTP.StackClient
)
import Network.HTTP.Simple ( getResponseHeader )
import Path
( (</>), addExtension, filename, parent, parseAbsDir
, parseAbsFile, parseRelDir, parseRelFile, toFilePath
( (</>), addExtension, filename, fromAbsDir, parent
, parseAbsDir, parseAbsFile, parseRelDir, parseRelFile
, toFilePath
)
import Path.CheckInstall ( warnInstallSearchPathIssues )
import Path.Extended ( fileExtension )
import Path.Extra ( toFilePathNoTrailingSep )
import Path.IO
( canonicalizePath, doesFileExist, ensureDir, executable
, getPermissions, ignoringAbsence, listDir, removeDirRecur
, renameDir, renameFile, resolveFile'
, renameDir, renameFile, resolveFile', withTempDir
)
import RIO.List
( headMaybe, intercalate, intersperse, isPrefixOf
Expand Down Expand Up @@ -165,7 +167,7 @@ import Stack.Types.VersionedDownloadInfo
import qualified System.Directory as D
import System.Environment ( getExecutablePath, lookupEnv )
import System.IO.Error ( isPermissionError )
import System.FilePath ( searchPathSeparator )
import System.FilePath ( searchPathSeparator, takeDrive )
import qualified System.FilePath as FP
import System.Permissions ( setFileExecutable )
import System.Uname ( getRelease )
Expand Down Expand Up @@ -2344,18 +2346,23 @@ withUnpackedTarball7z name si archiveFile archiveType destDir = do
-- We use a short name for the temporary directory 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.
let tmpName = "tmp"
let tmpName = "stack-tmp"
destDrive = fromJust $ parseAbsDir $ takeDrive $ fromAbsDir destDir
ensureDir (parent destDir)
withRunInIO $ \run ->
-- We use the system temporary directory 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.
withSystemTempDir tmpName $ \tmpDir ->
-- 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
run7z tmpDir (tmpDir </> tarFile)
absSrcDir <- expectSingleUnpackedDir archiveFile tmpDir
-- On Windows, 'renameDir' does not work across drives. However, we have
-- ensured that 'tmpDir' has the same drive as 'destDir'.
renameDir absSrcDir destDir

expectSingleUnpackedDir ::
Expand Down
4 changes: 1 addition & 3 deletions stack.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.0

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

Expand Down Expand Up @@ -40,10 +40,8 @@ extra-source-files:
doc/clean_command.md
doc/config_command.md
doc/CONTRIBUTING.md
doc/coverage.md
doc/custom_snapshot.md
doc/debugging.md
doc/dependency_visualization.md
doc/dev_containers.md
doc/developing_on_windows.md
doc/docker_command.md
Expand Down

0 comments on commit 63c3ad7

Please sign in to comment.