on master help sign in
Add some design/todo notes in the Dir module
c4c9bb4Harendra Kumar
core/src/Streamly/Internal/FileSystem/Dir.hs+38−2
@@ -13,10 +13,33 @@ module Streamly.Internal.FileSystem.Dir
13 (
13 (
14 -- * Streams
14 -- * Streams
15 read
15 read
16+
17+ -- read not just the names but also the inode attrs of the children. This
18+ -- abstraction makes sense because when we read the dir contents we also
19+ -- get the inodes, and it is cheaper to get the attrs from the inodes
20+ -- instead of resolving the paths and get those. This abstraction may be
21+ -- less portable as different platforms may have different attrs. To
22+ -- optimize, we can also add a filter/pattern/parser on the names of the
23+ -- children that we want to read. We can call that readAttrsWith? Or just
24+ -- have the default readAttrs do that? Usually we won't need that, so it
25+ -- may be better to keep that a separate API.
26+ -- , readAttrs
27+
28+ -- recursive read requires us to read the attributes of the children to
29+ -- determine if something is a dirctory or not. Therefore, it may be a good
30+ -- idea to have a low level routine that also spits out the attributes of
31+ -- the files, we get that for free. We can also add a filter/pattern/parser
32+ -- on the names of the children that we want to read.
33+ --, readAttrsRecursive -- Options: acyclic, follow symlinks
16 , readFiles
34 , readFiles
17 , readDirs
35 , readDirs
18 , readEither
36 , readEither
19− -- , readWithBufferOf
37+
38+ -- We can implement this in terms of readAttrsRecursive without losing
39+ -- perf.
40+ -- , readEitherRecursive -- Options: acyclic, follow symlinks
41+ -- , readAncestors -- read the parent chain using the .. entry.
42+ -- , readAncestorsAttrs
20
43
21 -- * Unfolds
44 -- * Unfolds
22 -- | Use the more convenient stream APIs instead of unfolds where possible.
45 -- | Use the more convenient stream APIs instead of unfolds where possible.
@@ -165,7 +188,7 @@ readChunks :: MonadIO m => Unfold m Handle (Array Word8)
165readChunks = UF.first readChunksWithBufferOf defaultChunkSize
188readChunks = UF.first readChunksWithBufferOf defaultChunkSize
166
189
167-------------------------------------------------------------------------------
190-------------------------------------------------------------------------------
168−-- Read File to Stream
191+-- Read a Directory to Stream
169-------------------------------------------------------------------------------
192-------------------------------------------------------------------------------
170
193
171-- TODO for concurrent streams implement readahead IO. We can send multiple
194-- TODO for concurrent streams implement readahead IO. We can send multiple
@@ -189,6 +212,19 @@ toStreamWithBufferOf :: MonadIO m => Int -> Handle -> Stream m Word8
189toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
212toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
190-}
213-}
191
214
215+-- read child node names from a dir filtering out . and ..
216+--
217+-- . and .. are an implementation artifact, and should probably not be used in
218+-- user level abstractions.
219+--
220+-- . does not seem to have any useful purpose. If we have the path of the dir
221+-- then we will resolve it to get the inode of the dir so the . entry would be
222+-- redundant. If we have the inode of the dir to read the dir then it is
223+-- redundant. Is this for cross check when doing fsck?
224+--
225+-- For .. we have the readAncestors API, we should not have this in the
226+-- readChildren API.
227+
192-- XXX exception handling
228-- XXX exception handling
193-- | Raw read of a directory
229-- | Raw read of a directory
194--
230--