Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Bug fixes:
by symlinks, while GCC will produce the object files in the original
directory. See
[#4402](https://github.com/commercialhaskell/stack/pull/4402)
* Fix handling of GitHub and URL templates on Windows. See
[commercialhaskell/stack#4394](https://github.com/commercialhaskell/stack/issues/4394)

## v1.9.1

Expand Down
10 changes: 5 additions & 5 deletions src/Stack/New.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ loadTemplate name logIt = do
case templatePath name of
AbsPath absFile -> logIt LocalTemp >> loadLocalFile absFile
UrlPath s -> downloadFromUrl s templateDir
RelPath relFile ->
RelPath rawParam relFile ->
catch
(do f <- loadLocalFile relFile
logIt LocalTemp
return f)
(\(e :: NewException) ->
case relRequest relFile of
case relRequest rawParam of
Just req -> downloadTemplate req
(templateDir </> relFile)
Nothing -> throwM e
Expand All @@ -141,9 +141,9 @@ loadTemplate name logIt = do
if exists
then readFileUtf8 (toFilePath path)
else throwM (FailedToLoadTemplate name (toFilePath path))
relRequest :: Path Rel File -> Maybe Request
relRequest rel = do
rtp <- parseRepoPathWithService defaultRepoService (T.pack (toFilePath rel))
relRequest :: String -> Maybe Request
relRequest req = do
rtp <- parseRepoPathWithService defaultRepoService (T.pack req)
let url = urlFromRepoTemplatePath rtp
parseRequest (T.unpack url)
downloadFromUrl :: String -> Path Abs Dir -> RIO env Text
Expand Down
9 changes: 5 additions & 4 deletions src/Stack/Types/TemplateName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ data TemplateName = TemplateName !Text !TemplatePath

data TemplatePath = AbsPath (Path Abs File)
-- ^ an absolute path on the filesystem
| RelPath (Path Rel File)
| RelPath String (Path Rel File)
-- ^ a relative path on the filesystem, or relative to
-- the template repository
-- the template repository. To avoid path separator conversion
-- on Windows, the raw command-line parameter passed is also
-- given as the first field (possibly with @.hsfiles@ appended).
| UrlPath String
-- ^ a full URL
| RepoPath RepoTemplatePath
Expand Down Expand Up @@ -91,7 +93,7 @@ parseTemplateNameFromString fname =
[ TemplateName prefix . RepoPath <$> parseRepoPath hsf
, TemplateName (T.pack orig) . UrlPath <$> (parseRequest orig *> Just orig)
, TemplateName prefix . AbsPath <$> parseAbsFile hsf
, TemplateName prefix . RelPath <$> parseRelFile hsf
, TemplateName prefix . RelPath hsf <$> parseRelFile hsf
]
expected = "Expected a template like: foo or foo.hsfiles or\
\ https://example.com/foo.hsfiles or github:user/foo"
Expand Down Expand Up @@ -133,4 +135,3 @@ parseRepoPathWithService service path =
repoUser <- defaultRepoUserForService service
Just $ RepoTemplatePath service repoUser name
_ -> Nothing

22 changes: 11 additions & 11 deletions src/test/Stack/Types/TemplateNameSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ spec =
pathOf "http://www.com/file" `shouldBe` UrlPath "http://www.com/file"
pathOf "https://www.com/file" `shouldBe` UrlPath "https://www.com/file"

pathOf "name" `shouldBe` (RelPath $ Path "name.hsfiles")
pathOf "name.hsfile" `shouldBe` (RelPath $ Path "name.hsfile.hsfiles")
pathOf "name.hsfiles" `shouldBe` (RelPath $ Path "name.hsfiles")
pathOf "" `shouldBe` (RelPath $ Path ".hsfiles")
pathOf "name" `shouldBe` (RelPath "name.hsfiles" $ Path "name.hsfiles")
pathOf "name.hsfile" `shouldBe` (RelPath "name.hsfile.hsfiles" $ Path "name.hsfile.hsfiles")
pathOf "name.hsfiles" `shouldBe` (RelPath "name.hsfiles" $ Path "name.hsfiles")
pathOf "" `shouldBe` (RelPath ".hsfiles" $ Path ".hsfiles")

if os == "mingw32"
then do
pathOf "//home/file" `shouldBe` (AbsPath $ Path "\\\\home\\file.hsfiles")
pathOf "/home/file" `shouldBe` (RelPath $ Path "\\home\\file.hsfiles")
pathOf "/home/file.hsfiles" `shouldBe` (RelPath $ Path "\\home\\file.hsfiles")
pathOf "/home/file" `shouldBe` (RelPath "/home/file.hsfiles" $ Path "\\home\\file.hsfiles")
pathOf "/home/file.hsfiles" `shouldBe` (RelPath "/home/file.hsfiles" $ Path "\\home\\file.hsfiles")

pathOf "c:\\home\\file" `shouldBe` (AbsPath $ Path "C:\\home\\file.hsfiles")
pathOf "with/slash" `shouldBe` (RelPath $ Path "with\\slash.hsfiles")
pathOf "c:\\home\\file" `shouldBe` (AbsPath $ Path "C:\\home\\file.hsfiles")
pathOf "with/slash" `shouldBe` (RelPath "with/slash.hsfiles" $ Path "with\\slash.hsfiles")

let colonAction =
do
Expand All @@ -45,7 +45,7 @@ spec =
pathOf "/home/file" `shouldBe` (AbsPath $ Path "/home/file.hsfiles")
pathOf "/home/file.hsfiles" `shouldBe` (AbsPath $ Path "/home/file.hsfiles")

pathOf "c:\\home\\file" `shouldBe` (RelPath $ Path "c:\\home\\file.hsfiles")
pathOf "with/slash" `shouldBe` (RelPath $ Path "with/slash.hsfiles")
pathOf "with:colon" `shouldBe` (RelPath $ Path "with:colon.hsfiles")
pathOf "c:\\home\\file" `shouldBe` (RelPath "c:\\home\\file.hsfiles" $ Path "c:\\home\\file.hsfiles")
pathOf "with/slash" `shouldBe` (RelPath "with/slash.hsfiles" $ Path "with/slash.hsfiles")
pathOf "with:colon" `shouldBe` (RelPath "with:colon.hsfiles" $ Path "with:colon.hsfiles")