@@ -13,10 +13,33 @@ module Streamly.Internal.FileSystem.Dir
1313 (
1414 -- * Streams
1515 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
1634 , readFiles
1735 , readDirs
1836 , 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
2043
2144 -- * Unfolds
2245 -- | Use the more convenient stream APIs instead of unfolds where possible.
@@ -165,7 +188,7 @@ readChunks :: MonadIO m => Unfold m Handle (Array Word8)
165188readChunks = UF.first readChunksWithBufferOf defaultChunkSize
166189
167190-------------------------------------------------------------------------------
168−-- Read File to Stream
191+-- Read a Directory to Stream
169192-------------------------------------------------------------------------------
170193
171194-- TODO for concurrent streams implement readahead IO. We can send multiple
@@ -189,6 +212,19 @@ toStreamWithBufferOf :: MonadIO m => Int -> Handle -> Stream m Word8
189212toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
190213-}
191214
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+
192228-- XXX exception handling
193229-- | Raw read of a directory
194230--