Skip to content

Commit

Permalink
Fix build failures and bugs on Windows (#436)
Browse files Browse the repository at this point in the history
Fixes #434
  • Loading branch information
Gabriella439 authored Jun 17, 2022
1 parent af8c16e commit 38e76e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/Turtle/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -982,13 +982,12 @@ ls path = Shell (\(FoldShell step begin done) -> do
reparse <- fmap reparsePoint (Win32.getFileAttributes path')
if (canRead && not reparse)
then bracket
(Win32.findFirstFile (Filesystem.encodeString (path </> "*")))
(Win32.findFirstFile (path </> "*"))
(\(h, _) -> Win32.findClose h)
(\(h, fdat) -> do
let loop x = do
file' <- Win32.getFindDataFileName fdat
let file = Filesystem.decodeString file'
x' <- if (file' /= "." && file' /= "..")
file <- Win32.getFindDataFileName fdat
x' <- if (file /= "." && file /= "..")
then step x (path </> file)
else return x
more <- Win32.findNextFile h fdat
Expand Down Expand Up @@ -1131,7 +1130,7 @@ cptree oldTree newTree = sh (do
-- a directory and fails to strip it as a prefix from `/tmp/foo`. Adding
-- `(</> "")` to the end of the path makes clear that the path is a
-- directory
Just suffix <- return (Internal.stripPrefix (oldTree ++ "/") oldPath)
Just suffix <- return (Internal.stripPrefix (oldTree <> [ FilePath.pathSeparator ]) oldPath)

let newPath = newTree </> suffix

Expand Down Expand Up @@ -1221,7 +1220,7 @@ touch file = do
#ifdef mingw32_HOST_OS
then do
handle <- Win32.createFile
(Filesystem.encodeString file)
file
Win32.gENERIC_WRITE
Win32.fILE_SHARE_NONE
Nothing
Expand Down
19 changes: 16 additions & 3 deletions test/system-filepath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ main = defaultMain $ testGroup "system-filepath tests"
test_Root :: TestTree
test_Root = testCase "root" $ do
"" @=? root ""
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
"c:\\" @=? root "c:\\"
"c:\\" @=? root "c:\\foo"
#else
"/" @=? root "/"
"" @=? root "foo"
"/" @=? root "/foo"
#endif
"" @=? root "foo"

test_Directory :: TestTree
test_Directory = testCase "directory" $ do
Expand Down Expand Up @@ -59,7 +64,11 @@ test_Parent = testCase "parent" $ do
"../" @=? parent "../.."
"../" @=? parent "../."

#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
"c:\\" @=? parent "c:\\"
#else
"/" @=? parent "/"
#endif
"./" @=? parent "foo"
"./" @=? parent "./foo"
"./foo/" @=? parent "foo/bar"
Expand Down Expand Up @@ -138,7 +147,6 @@ test_Relative = testCase "relative" $ do
myAssert' "c:\\foo\\bar"
myAssert ""
myAssert "foo\\bar"
myAssert' "\\foo\\bar"
#else
myAssert' "/"
myAssert' "/foo/bar"
Expand Down Expand Up @@ -179,10 +187,15 @@ test_Collapse :: TestTree
test_Collapse = testCase "collapse" $ do
-- This behavior differs from the old `system-filepath` package, but this
-- behavior is more correct in the presence of symlinks
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
"foo\\..\\bar" @=? collapse "foo/../bar"
"foo\\bar" @=? collapse "foo/bar"
"foo\\bar" @=? collapse "foo/./bar"
#else
"foo/../bar" @=? collapse "foo/../bar"

"foo/bar" @=? collapse "foo/bar"
"foo/bar" @=? collapse "foo/./bar"
#endif

test_SplitDirectories :: TestTree
test_SplitDirectories = testCase "splitDirectories" $ do
Expand Down

0 comments on commit 38e76e1

Please sign in to comment.