on master help sign in
Remove IsStream import from FileSystem.Event.* modules (#1849)
70e4a57Ranjeet Ranjan
src/Streamly/Internal/FileSystem/Event/Linux.hs+6−5
@@ -185,7 +185,7 @@ import qualified Streamly.Internal.Data.Array.Unboxed as A
185import qualified Streamly.Data.Fold as FL
185import qualified Streamly.Data.Fold as FL
186import qualified Streamly.Internal.Data.Parser as PR
186import qualified Streamly.Internal.Data.Parser as PR
187 (takeEQ, fromEffect, fromFold)
187 (takeEQ, fromEffect, fromFold)
188−import qualified Streamly.Internal.Data.Stream.IsStream as S
188+import qualified Streamly.Internal.Data.Stream as S
189import qualified Streamly.Internal.FileSystem.Dir as Dir
189import qualified Streamly.Internal.FileSystem.Dir as Dir
190import qualified Streamly.Internal.FileSystem.Handle as FH
190import qualified Streamly.Internal.FileSystem.Handle as FH
191import qualified Streamly.Internal.Unicode.Stream as U
191import qualified Streamly.Internal.Unicode.Stream as U
@@ -624,7 +624,7 @@ toUtf8 :: MonadIO m => String -> m (Array Word8)
624toUtf8 = A.fromStream . U.encodeUtf8 . S.fromList
624toUtf8 = A.fromStream . U.encodeUtf8 . S.fromList
625
625
626utf8ToString :: Array Word8 -> String
626utf8ToString :: Array Word8 -> String
627−utf8ToString = runIdentity . S.toList . U.decodeUtf8' . A.toStream
627+utf8ToString = runIdentity . S.fold FL.toList . U.decodeUtf8' . A.toStream
628
628
629-- | Add a trailing "/" at the end of the path if there is none. Do not add a
629-- | Add a trailing "/" at the end of the path if there is none. Do not add a
630-- "/" if the path is empty.
630-- "/" if the path is empty.
@@ -723,9 +723,10 @@ addToWatch cfg@Config{..} watch0@(Watch handle wdMap) root0 path0 = do
723 -- to "/" separated by byte arrays.
723 -- to "/" separated by byte arrays.
724 pathIsDir <- doesDirectoryExist $ utf8ToString absPath
724 pathIsDir <- doesDirectoryExist $ utf8ToString absPath
725 when (watchRec && pathIsDir) $ do
725 when (watchRec && pathIsDir) $ do
726− S.mapM_ (\p -> addToWatch cfg watch0 root (appendPaths path p))
726+ let f = addToWatch cfg watch0 root . appendPaths path
727+ in S.fold (FL.drainBy f)
727− $ S.mapM toUtf8
728+ $ S.mapM toUtf8
728− $ Dir.toDirs $ utf8ToString absPath
729+ $ Dir.toDirs $ utf8ToString absPath
729
730
730foreign import ccall unsafe
731foreign import ccall unsafe
731 "sys/inotify.h inotify_rm_watch" c_inotify_rm_watch
732 "sys/inotify.h inotify_rm_watch" c_inotify_rm_watch
src/Streamly/Internal/FileSystem/Event/Windows.hs+9−5
@@ -121,7 +121,8 @@ import System.Win32.File
121 )
121 )
122import System.Win32.Types (BOOL, DWORD, HANDLE, LPVOID, LPDWORD, failIfFalse_)
122import System.Win32.Types (BOOL, DWORD, HANDLE, LPVOID, LPDWORD, failIfFalse_)
123import qualified Data.List.NonEmpty as NonEmpty
123import qualified Data.List.NonEmpty as NonEmpty
124−import qualified Streamly.Internal.Data.Stream.IsStream as S
124+import qualified Streamly.Data.Fold as Fold
125+import qualified Streamly.Internal.Data.Stream as S
125import qualified Streamly.Internal.Unicode.Stream as U
126import qualified Streamly.Internal.Unicode.Stream as U
126import qualified Streamly.Internal.Unicode.Utf8 as UTF8
127import qualified Streamly.Internal.Unicode.Utf8 as UTF8
127import qualified Streamly.Internal.Data.Array.Unboxed as A
128import qualified Streamly.Internal.Data.Array.Unboxed as A
@@ -416,7 +417,8 @@ eventStreamAggr :: (HANDLE, FilePath, Config) -> Stream IO Event
416eventStreamAggr (handle, rootPath, cfg) = do
417eventStreamAggr (handle, rootPath, cfg) = do
417 let recMode = getConfigRecMode cfg
418 let recMode = getConfigRecMode cfg
418 flagMasks = getConfigFlag cfg
419 flagMasks = getConfigFlag cfg
420+ repeatM = S.sequence . S.repeat
419− S.concatMap S.fromList $ S.repeatM
421+ S.concatMap S.fromList $ repeatM
420 $ readDirectoryChanges rootPath handle recMode flagMasks
422 $ readDirectoryChanges rootPath handle recMode flagMasks
421
423
422pathsToHandles ::
424pathsToHandles ::
@@ -424,14 +426,14 @@ pathsToHandles ::
424pathsToHandles paths cfg = do
426pathsToHandles paths cfg = do
425 let pathStream = S.fromList (NonEmpty.toList paths)
427 let pathStream = S.fromList (NonEmpty.toList paths)
426 st2 = S.mapM getWatchHandle pathStream
428 st2 = S.mapM getWatchHandle pathStream
427− S.map (\(h, f) -> (h, f, cfg)) st2
429+ fmap (\(h, f) -> (h, f, cfg)) st2
428
430
429-------------------------------------------------------------------------------
431-------------------------------------------------------------------------------
430-- Utilities
432-- Utilities
431-------------------------------------------------------------------------------
433-------------------------------------------------------------------------------
432
434
433utf8ToString :: Array Word8 -> FilePath
435utf8ToString :: Array Word8 -> FilePath
434−utf8ToString = runIdentity . S.toList . U.decodeUtf8 . A.toStream
436+utf8ToString = runIdentity . S.fold Fold.toList . U.decodeUtf8 . A.toStream
435
437
436utf8ToStringList :: NonEmpty (Array Word8) -> NonEmpty FilePath
438utf8ToStringList :: NonEmpty (Array Word8) -> NonEmpty FilePath
437utf8ToStringList = NonEmpty.map utf8ToString
439utf8ToStringList = NonEmpty.map utf8ToString
@@ -439,7 +441,9 @@ utf8ToStringList = NonEmpty.map utf8ToString
439-- | Close a Directory handle.
441-- | Close a Directory handle.
440--
442--
441closePathHandleStream :: Stream IO (HANDLE, FilePath, Config) -> IO ()
443closePathHandleStream :: Stream IO (HANDLE, FilePath, Config) -> IO ()
442−closePathHandleStream = S.mapM_ (\(h, _, _) -> closeHandle h)
444+closePathHandleStream =
445+ let f (h, _, _) = closeHandle h
446+ in S.fold (Fold.drainBy f)
443
447
444-- XXX
448-- XXX
445-- Document the path treatment for Linux/Windows/macOS modules.
449-- Document the path treatment for Linux/Windows/macOS modules.