on master help sign in
Remove IsStream import from FileSystem.Event.* modules (#1849)
commit70e4a574164dac0b9c4d1169f6667bce062ec10d authorRanjeet Ranjan <ranjeetr@composewell.com> dateThu 29 Sep 2022, 02:09 (4 years ago) parent182edfd
2 files changed+15−10
src/Streamly/Internal/FileSystem/Event/Linux.hs+6−5 src/Streamly/Internal/FileSystem/Event/Windows.hs+9−5
src/Streamly/Internal/FileSystem/Event/Linux.hs+6−5
@@ -185,7 +185,7 @@ import qualified Streamly.Internal.Data.Array.Unboxed as A
185185import qualified Streamly.Data.Fold as FL
186186import qualified Streamly.Internal.Data.Parser as PR
187187 (takeEQ, fromEffect, fromFold)
188−import qualified Streamly.Internal.Data.Stream.IsStream as S
188+import qualified Streamly.Internal.Data.Stream as S
189189import qualified Streamly.Internal.FileSystem.Dir as Dir
190190import qualified Streamly.Internal.FileSystem.Handle as FH
191191import qualified Streamly.Internal.Unicode.Stream as U
@@ -624,7 +624,7 @@ toUtf8 :: MonadIO m => String -> m (Array Word8)
624624toUtf8 = A.fromStream . U.encodeUtf8 . S.fromList
625625
626626utf8ToString :: Array Word8 -> String
627−utf8ToString = runIdentity . S.toList . U.decodeUtf8' . A.toStream
627+utf8ToString = runIdentity . S.fold FL.toList . U.decodeUtf8' . A.toStream
628628
629629-- | Add a trailing "/" at the end of the path if there is none. Do not add a
630630-- "/" if the path is empty.
@@ -723,9 +723,10 @@ addToWatch cfg@Config{..} watch0@(Watch handle wdMap) root0 path0 = do
723723 -- to "/" separated by byte arrays.
724724 pathIsDir <- doesDirectoryExist $ utf8ToString absPath
725725 when (watchRec && pathIsDir) $ do
726− S.mapM_ (\p -> addToWatch cfg watch0 root (appendPaths path p))
727− $ S.mapM toUtf8
728− $ Dir.toDirs $ utf8ToString absPath
726+ let f = addToWatch cfg watch0 root . appendPaths path
727+ in S.fold (FL.drainBy f)
728+ $ S.mapM toUtf8
729+ $ Dir.toDirs $ utf8ToString absPath
729730
730731foreign import ccall unsafe
731732 "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
121121 )
122122import System.Win32.Types (BOOL, DWORD, HANDLE, LPVOID, LPDWORD, failIfFalse_)
123123import 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
125126import qualified Streamly.Internal.Unicode.Stream as U
126127import qualified Streamly.Internal.Unicode.Utf8 as UTF8
127128import qualified Streamly.Internal.Data.Array.Unboxed as A
@@ -416,7 +417,8 @@ eventStreamAggr :: (HANDLE, FilePath, Config) -> Stream IO Event
416417eventStreamAggr (handle, rootPath, cfg) = do
417418 let recMode = getConfigRecMode cfg
418419 flagMasks = getConfigFlag cfg
419− S.concatMap S.fromList $ S.repeatM
420+ repeatM = S.sequence . S.repeat
421+ S.concatMap S.fromList $ repeatM
420422 $ readDirectoryChanges rootPath handle recMode flagMasks
421423
422424pathsToHandles ::
@@ -424,14 +426,14 @@ pathsToHandles ::
424426pathsToHandles paths cfg = do
425427 let pathStream = S.fromList (NonEmpty.toList paths)
426428 st2 = S.mapM getWatchHandle pathStream
427− S.map (\(h, f) -> (h, f, cfg)) st2
429+ fmap (\(h, f) -> (h, f, cfg)) st2
428430
429431-------------------------------------------------------------------------------
430432-- Utilities
431433-------------------------------------------------------------------------------
432434
433435utf8ToString :: Array Word8 -> FilePath
434−utf8ToString = runIdentity . S.toList . U.decodeUtf8 . A.toStream
436+utf8ToString = runIdentity . S.fold Fold.toList . U.decodeUtf8 . A.toStream
435437
436438utf8ToStringList :: NonEmpty (Array Word8) -> NonEmpty FilePath
437439utf8ToStringList = NonEmpty.map utf8ToString
@@ -439,7 +441,9 @@ utf8ToStringList = NonEmpty.map utf8ToString
439441-- | Close a Directory handle.
440442--
441443closePathHandleStream :: 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)
443447
444448-- XXX
445449-- Document the path treatment for Linux/Windows/macOS modules.