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
4 changes: 2 additions & 2 deletions bench-test-lib/src/BenchTestLib/DirIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ listDirChunkedWith
-> [Char] -> Stream IO Word8
listDirChunkedWith act inp = do
Stream.unfoldEachEndBy 10 Array.reader
$ fmap Path.toChunk
$ fmap (Array.asBytes . Path.toChunk)
$ Stream.unfoldEach Unfold.fromList
$ fmap (either id id)
$ act
Expand All @@ -177,7 +177,7 @@ listDirWith
-> [Char] -> Stream IO Word8
listDirWith act inp = do
Stream.unfoldEachEndBy 10 Array.reader
$ fmap (Path.toChunk . either id id)
$ fmap (Array.asBytes . Path.toChunk . either id id)
$ act
$ Stream.fromPure (Left (fromJust $ Path.fromString inp))

Expand Down
6 changes: 0 additions & 6 deletions core/src/Streamly/Internal/FileSystem/Path/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module Streamly.Internal.FileSystem.Path.Common
, mkQ

-- * Elimination
, toChunk
, toString
, toChars

Expand Down Expand Up @@ -1206,11 +1205,6 @@ fromChunk Windows arr =
Just x -> validatePath Windows x >> pure x
-}

-- | Convert 'Path' to an array of bytes.
{-# INLINE toChunk #-}
toChunk :: Array a -> Array Word8
toChunk = Array.asBytes

{-# INLINE unsafeFromChars #-}
unsafeFromChars :: (Unbox a) =>
(Stream Identity Char -> Stream Identity a)
Expand Down
38 changes: 10 additions & 28 deletions core/src/Streamly/Internal/FileSystem/PosixPath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,11 @@ import Control.Monad.Catch (MonadThrow(..))
import Data.Bifunctor (bimap)
import Data.Functor.Identity (Identity(..))
import Data.Maybe (fromJust)
import Data.Word (Word8)
#if defined(IS_WINDOWS)
import Data.Word (Word16)
#endif
#ifndef IS_WINDOWS
import Data.Word (Word8)
import Foreign.C (CString)
#else
import Data.Word (Word16)
import Foreign.C (CWString)
#endif
import Language.Haskell.TH.Syntax (lift)
Expand Down Expand Up @@ -304,11 +302,7 @@ addTrailingSeparator p = unsafeAppend p sep

-- | Throws an exception if the path is not valid. See 'isValidPath' for the
-- list of validations.
#ifndef IS_WINDOWS
validatePath :: MonadThrow m => Array Word8 -> m ()
#else
validatePath :: MonadThrow m => Array Word16 -> m ()
#endif
validatePath :: MonadThrow m => Array WORD_TYPE -> m ()
validatePath = Common.validatePath Common.OS_NAME

#ifndef IS_WINDOWS
Expand All @@ -322,7 +316,7 @@ validatePath = Common.validatePath Common.OS_NAME
-- >>> isValid "\0"
-- False
--
isValidPath :: Array Word8 -> Bool
isValidPath :: Array WORD_TYPE -> Bool
isValidPath = Common.isValidPath Common.OS_NAME
#endif

Expand All @@ -342,11 +336,7 @@ isValidPath = Common.isValidPath Common.OS_NAME
-- per 'isValidPath'.
--
{-# INLINE unsafeFromChunk #-}
#ifndef IS_WINDOWS
unsafeFromChunk :: IsPath OS_PATH a => Array Word8 -> a
#else
unsafeFromChunk :: IsPath OS_PATH a => Array Word16 -> a
#endif
unsafeFromChunk :: IsPath OS_PATH a => Array WORD_TYPE -> a
unsafeFromChunk =
#ifndef DEBUG
unsafeFromPath . OS_PATH . Common.unsafeFromChunk
Expand All @@ -359,11 +349,7 @@ unsafeFromChunk =
-- | Convert a byte array into a Path.
-- Throws 'InvalidPath' if 'isValidPath' fails on the path.
--
#ifndef IS_WINDOWS
fromChunk :: (MonadThrow m, IsPath OS_PATH a) => Array Word8 -> m a
#else
fromChunk :: (MonadThrow m, IsPath OS_PATH a) => Array Word16 -> m a
#endif
fromChunk :: (MonadThrow m, IsPath OS_PATH a) => Array WORD_TYPE -> m a
fromChunk arr = Common.fromChunk Common.OS_NAME arr >>= fromPath . OS_PATH

-- XXX Should be a Fold instead?
Expand Down Expand Up @@ -391,11 +377,7 @@ fromChars s =

-- | Create a raw path i.e. an array representing the path. Note that the path
-- is not validated, therefore, it may not be valid according to 'isValidPath'.
#ifndef IS_WINDOWS
rawFromString :: [Char] -> Array Word8
#else
rawFromString :: [Char] -> Array Word16
#endif
rawFromString :: [Char] -> Array WORD_TYPE
rawFromString =
Common.unsafeFromChars Unicode.UNICODE_ENCODER
. Stream.fromList
Expand Down Expand Up @@ -472,9 +454,9 @@ path = mkQ pathE

-- XXX unPath?

-- | Convert the path to an array of bytes.
toChunk :: IsPath OS_PATH a => a -> Array Word8
toChunk p = let OS_PATH arr = toPath p in Common.toChunk arr
-- | Convert the path to an array.
toChunk :: IsPath OS_PATH a => a -> Array WORD_TYPE
toChunk p = let OS_PATH arr = toPath p in arr

-- | Decode the path to a stream of Unicode chars using strict CODEC_NAME decoding.
{-# INLINE toChars #-}
Expand Down
10 changes: 6 additions & 4 deletions core/src/Streamly/Internal/FileSystem/WindowsPath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,21 @@ For APIs that have not been released yet.
-- True
-- >>> isValid "\\\\??\\x"
-- True
isValidPath :: Array Word16 -> Bool
isValidPath :: Array WORD_TYPE -> Bool
isValidPath = Common.isValidPath Common.OS_NAME

-- | Like 'validatePath' on but more strict. A share root must be followed by a
-- non-empty path. Thus "\/\/x\/" is not considered a valid path.
validatePath' :: MonadThrow m => Array Word16 -> m ()
validatePath' ::
MonadThrow m => Array WORD_TYPE -> m ()
validatePath' = Common.validatePath' Common.Windows

-- | Like 'isValidPath' but more strict, see validatePath' for differences.
isValidPath' :: Array Word16 -> Bool
isValidPath' ::
Array WORD_TYPE -> Bool
isValidPath' = Common.isValidPath' Common.Windows

-- | Read a raw array of Word16 as a path type.
-- | Read a raw array of WORD_TYPE as a path type.
--
-- >>> readRaw = fromJust . Path.fromChunk . read
--
Expand Down
Loading