on master help sign in
Rename unfold APIs in FileSystem.Dir module
c02ffa4Harendra Kumar
src/Streamly/Internal/FileSystem/Dir.hs+49−21
@@ -11,17 +11,20 @@
11
11
12module Streamly.Internal.FileSystem.Dir
12module Streamly.Internal.FileSystem.Dir
13 (
13 (
14− -- ** Read from Directory
14+ -- * Streams
15 read
15 read
16 , readFiles
16 , readFiles
17 , readDirs
17 , readDirs
18 , readEither
18 , readEither
19 -- , readWithBufferOf
19 -- , readWithBufferOf
20
20
21− , toStream
21+ -- * Unfolds
22− , toEither
22+ -- | Use the more convenient stream APIs instead of unfolds where possible.
23− , toFiles
23+ , reader
24− , toDirs
24+ , fileReader
25+ , dirReader
26+ , eitherReader
27+
25 {-
28 {-
26 , toStreamWithBufferOf
29 , toStreamWithBufferOf
27
30
@@ -47,6 +50,11 @@ module Streamly.Internal.FileSystem.Dir
47 , fromChunks
50 , fromChunks
48 , fromChunksWithBufferOf
51 , fromChunksWithBufferOf
49 -}
52 -}
53+ -- * Deprecated
54+ , toStream
55+ , toEither
56+ , toFiles
57+ , toDirs
50 )
58 )
51where
59where
52
60
@@ -186,9 +194,9 @@ toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
186--
194--
187-- /Internal/
195-- /Internal/
188--
196--
189−{-# INLINE read #-}
197+{-# INLINE reader #-}
190−read :: MonadIO m => Unfold m String String
198+reader :: MonadIO m => Unfold m String String
191−read =
199+reader =
192 -- XXX use proper streaming read of the dir
200 -- XXX use proper streaming read of the dir
193 UF.lmapM (liftIO . Dir.getDirectoryContents) UF.fromList
201 UF.lmapM (liftIO . Dir.getDirectoryContents) UF.fromList
194
202
@@ -202,9 +210,9 @@ read =
202--
210--
203-- /Internal/
211-- /Internal/
204--
212--
205−{-# INLINE readEither #-}
213+{-# INLINE eitherReader #-}
206−readEither :: MonadIO m => Unfold m String (Either String String)
214+eitherReader :: MonadIO m => Unfold m String (Either String String)
207−readEither =
215+eitherReader =
208 UF.mapM2 classify
216 UF.mapM2 classify
209 $ UF.filter (\x -> x /= "." && x /= "..")
217 $ UF.filter (\x -> x /= "." && x /= "..")
210 -- XXX use proper streaming read of the dir
218 -- XXX use proper streaming read of the dir
@@ -219,48 +227,68 @@ readEither =
219--
227--
220-- /Internal/
228-- /Internal/
221--
229--
222−{-# INLINE readFiles #-}
230+{-# INLINE fileReader #-}
223−readFiles :: MonadIO m => Unfold m String String
231+fileReader :: MonadIO m => Unfold m String String
224−readFiles = fmap (fromRight undefined) $ UF.filter isRight readEither
232+fileReader = fmap (fromRight undefined) $ UF.filter isRight eitherReader
225
233
226-- | Read directories only. Filter out "." and ".." entries.
234-- | Read directories only. Filter out "." and ".." entries.
227--
235--
228-- /Internal/
236-- /Internal/
229--
237--
230−{-# INLINE readDirs #-}
238+{-# INLINE dirReader #-}
231−readDirs :: MonadIO m => Unfold m String String
239+dirReader :: MonadIO m => Unfold m String String
232−readDirs = fmap (fromLeft undefined) $ UF.filter isLeft readEither
240+dirReader = fmap (fromLeft undefined) $ UF.filter isLeft eitherReader
233
241
234-- | Raw read of a directory.
242-- | Raw read of a directory.
235--
243--
236-- /Pre-release/
244-- /Pre-release/
245+{-# INLINE read #-}
246+read :: MonadIO m => String -> Stream m String
247+read = S.unfold reader
248+
249+{-# DEPRECATED toStream "Please use 'read' instead" #-}
237{-# INLINE toStream #-}
250{-# INLINE toStream #-}
238toStream :: MonadIO m => String -> Stream m String
251toStream :: MonadIO m => String -> Stream m String
239−toStream = S.unfold read
252+toStream = read
240
253
241-- | Read directories as Left and files as Right. Filter out "." and ".."
254-- | Read directories as Left and files as Right. Filter out "." and ".."
242-- entries.
255-- entries.
243--
256--
244-- /Pre-release/
257-- /Pre-release/
258+{-# INLINE readEither #-}
259+readEither :: MonadIO m => String -> Stream m (Either String String)
260+readEither = S.unfold eitherReader
261+
262+{-# DEPRECATED toEither "Please use 'readEither' instead" #-}
245{-# INLINE toEither #-}
263{-# INLINE toEither #-}
246toEither :: MonadIO m => String -> Stream m (Either String String)
264toEither :: MonadIO m => String -> Stream m (Either String String)
247−toEither = S.unfold readEither
265+toEither = readEither
248
266
249-- | Read files only.
267-- | Read files only.
250--
268--
251-- /Internal/
269-- /Internal/
252--
270--
271+{-# INLINE readFiles #-}
272+readFiles :: MonadIO m => String -> Stream m String
273+readFiles = S.unfold fileReader
274+
275+{-# DEPRECATED toFiles "Please use 'readFiles' instead" #-}
253{-# INLINE toFiles #-}
276{-# INLINE toFiles #-}
254toFiles :: MonadIO m => String -> Stream m String
277toFiles :: MonadIO m => String -> Stream m String
255−toFiles = S.unfold readFiles
278+toFiles = readFiles
256
279
257-- | Read directories only.
280-- | Read directories only.
258--
281--
259-- /Internal/
282-- /Internal/
260--
283--
284+{-# INLINE readDirs #-}
285+readDirs :: MonadIO m => String -> Stream m String
286+readDirs = S.unfold dirReader
287+
288+{-# DEPRECATED toDirs "Please use 'readDirs' instead" #-}
261{-# INLINE toDirs #-}
289{-# INLINE toDirs #-}
262toDirs :: MonadIO m => String -> Stream m String
290toDirs :: MonadIO m => String -> Stream m String
263−toDirs = S.unfold readDirs
291+toDirs = readDirs
264
292
265{-
293{-
266-------------------------------------------------------------------------------
294-------------------------------------------------------------------------------
src/Streamly/Internal/FileSystem/Event/Linux.hs+2−2
@@ -719,14 +719,14 @@ addToWatch cfg@Config{..} watch0@(Watch handle wdMap) root0 path0 = do
719 -- XXX Ensure that we generate events that we may have missed while we were
719 -- XXX Ensure that we generate events that we may have missed while we were
720 -- adding the dirs. That may generate spurious events though.
720 -- adding the dirs. That may generate spurious events though.
721 --
721 --
722− -- XXX toDirs currently uses paths as String, we need to convert it
722+ -- XXX readDirs currently uses paths as String, we need to convert it
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 let f = addToWatch cfg watch0 root . appendPaths path
726 let f = addToWatch cfg watch0 root . appendPaths path
727 in S.fold (FL.drainBy f)
727 in S.fold (FL.drainBy f)
728 $ S.mapM toUtf8
728 $ S.mapM toUtf8
729− $ Dir.toDirs $ utf8ToString absPath
729+ $ Dir.readDirs $ utf8ToString absPath
730
730
731foreign import ccall unsafe
731foreign import ccall unsafe
732 "sys/inotify.h inotify_rm_watch" c_inotify_rm_watch
732 "sys/inotify.h inotify_rm_watch" c_inotify_rm_watch