Skip to content

Commit 66090f3

Browse files
committed
Fix --docker for Windows. Fix commercialhaskell#2421.
1 parent 1b1bed5 commit 66090f3

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/Stack/Docker.hs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ getCmdArgs
7878
getCmdArgs docker imageInfo isRemoteDocker = do
7979
config <- view configL
8080
deUser <-
81-
if fromMaybe (not isRemoteDocker) (dockerSetUser docker)
81+
if fromMaybe (not isRemoteDocker) (dockerSetUser docker) && not osIsWindows
8282
then liftIO $ do
8383
duUid <- User.getEffectiveUserID
8484
duGid <- User.getEffectiveGroupID
@@ -244,7 +244,7 @@ runContainerAndExit = do
244244
liftIO
245245
(Files.fileExist
246246
(toFilePathNoTrailingSep (sandboxHomeDir </> sshRelDir)))
247-
when (sshDirExists && not sshSandboxDirExists)
247+
when (sshDirExists && not sshSandboxDirExists && not osIsWindows)
248248
(liftIO
249249
(Files.createSymbolicLink
250250
(toFilePathNoTrailingSep sshDir)
@@ -254,16 +254,16 @@ runContainerAndExit = do
254254
(concat
255255
[["create"
256256
,"-e",inContainerEnvVar ++ "=1"
257-
,"-e",stackRootEnvVar ++ "=" ++ toFilePathNoTrailingSep stackRoot
257+
,"-e",stackRootEnvVar ++ "=" ++ toLinuxStylePath (toFilePathNoTrailingSep stackRoot)
258258
,"-e",platformVariantEnvVar ++ "=dk" ++ platformVariant
259-
,"-e","HOME=" ++ toFilePathNoTrailingSep sandboxHomeDir
259+
,"-e","HOME=" ++ toLinuxStylePath (toFilePathNoTrailingSep sandboxHomeDir)
260260
,"-e","PATH=" ++ T.unpack newPathEnv
261-
,"-e","PWD=" ++ toFilePathNoTrailingSep pwd
262-
,"-v",toFilePathNoTrailingSep homeDir ++ ":" ++ toFilePathNoTrailingSep homeDir ++ mountSuffix
263-
,"-v",toFilePathNoTrailingSep stackRoot ++ ":" ++ toFilePathNoTrailingSep stackRoot ++ mountSuffix
264-
,"-v",toFilePathNoTrailingSep projectRoot ++ ":" ++ toFilePathNoTrailingSep projectRoot ++ mountSuffix
265-
,"-v",toFilePathNoTrailingSep sandboxHomeDir ++ ":" ++ toFilePathNoTrailingSep sandboxHomeDir ++ mountSuffix
266-
,"-w",toFilePathNoTrailingSep pwd]
261+
,"-e","PWD=" ++ toLinuxStylePath (toFilePathNoTrailingSep pwd)
262+
,"-v",toFilePathNoTrailingSep homeDir ++ ":" ++ toLinuxStylePath (toFilePathNoTrailingSep homeDir ++ mountSuffix)
263+
,"-v",toFilePathNoTrailingSep stackRoot ++ ":" ++ toLinuxStylePath (toFilePathNoTrailingSep stackRoot ++ mountSuffix)
264+
,"-v",toFilePathNoTrailingSep projectRoot ++ ":" ++ toLinuxStylePath (toFilePathNoTrailingSep projectRoot ++ mountSuffix)
265+
,"-v",toFilePathNoTrailingSep sandboxHomeDir ++ ":" ++ toLinuxStylePath (toFilePathNoTrailingSep sandboxHomeDir ++ mountSuffix)
266+
,"-w", toLinuxStylePath (toFilePathNoTrailingSep pwd)]
267267
,case dockerNetwork docker of
268268
Nothing -> ["--net=host"]
269269
Just name -> ["--net=" ++ name]
@@ -340,6 +340,13 @@ runContainerAndExit = do
340340
mountArg mountSuffix (Mount host container) =
341341
["-v",host ++ ":" ++ container ++ mountSuffix]
342342
sshRelDir = relDirDotSsh
343+
toLinuxStylePath s | osIsWindows =
344+
T.pack s
345+
& T.replace ":\\" "/"
346+
& T.replace "\\" "/"
347+
& T.unpack
348+
& ("/"++)
349+
| otherwise = s
343350

344351
-- | Inspect Docker image or container.
345352
inspect :: (HasProcessContext env, HasLogFunc env)

0 commit comments

Comments
 (0)