99module Streamly.Internal.FileSystem.Posix.ReadDir
1010 (
1111#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
12- ReadOptions
13- , followSymlinks
14- , ignoreMissing
15- , ignoreSymlinkLoops
16- , ignoreInaccessible
17- , defaultReadOptions
18-
19- , readScanWith_
12+ readScanWith_
2013 , readScanWith
2114 , readPlusScanWith
2215
@@ -68,6 +61,8 @@ import qualified Streamly.Internal.Data.Unfold as UF (bracketIO)
6861import qualified Streamly.Internal.FileSystem.Path.Common as PathC
6962import qualified Streamly.Internal.FileSystem.PosixPath as Path
7063
64+ import Streamly.Internal.FileSystem.DirOptions
65+
7166#include <dirent.h>
7267#include <sys/stat.h>
7368
@@ -79,103 +74,6 @@ data {-# CTYPE "struct stat" #-} CStat
7974
8075newtype DirStream = DirStream (Ptr CDir )
8176
82- -- NOTE: If we are following symlinks, then we want to determine the type of
83- -- the link destination not the link itself, so we need to use stat instead of
84- -- lstat for resolving the symlink.
85- --
86- -- For recursive traversal, instead of classifying the dirents using stat, we
87- -- can leave them unclassified, and deal with ENOTDIR when doing an opendir. We
88- -- can just ignore that error if it is not a dir. This way we do not need to do
89- -- stat at all. Or we can basically say don't try to determine the type of
90- -- symlinks and always try to read symlinks as dirs. We can have an option for
91- -- classifying symlinks or DT_UNKNOWN as potential dirs.
92-
93- -- When resolving a symlink we may encounter errors only if the directory entry
94- -- is a symlink. If the directory entry is not a symlink then stat on it will
95- -- have permissions, it will not give ELOOP or ENOENT unless the file was
96- -- deleted or recreated after we read the dirent.
97-
98- -- | Options controlling the behavior of directory read.
99- data ReadOptions =
100- ReadOptions
101- { _followSymlinks :: Bool
102- , _ignoreELOOP :: Bool
103- , _ignoreENOENT :: Bool
104- , _ignoreEACCESS :: Bool
105- }
106-
107- -- | Control how symbolic links are handled when determining the type
108- -- of a directory entry.
109- --
110- -- * If set to 'True', symbolic links are resolved before classification.
111- -- This means a symlink pointing to a directory will be treated as a
112- -- directory, and a symlink pointing to a file will be treated as a
113- -- non-directory.
114- --
115- -- * If set to 'False', all symbolic links are classified as non-directories,
116- -- without attempting to resolve their targets.
117- --
118- -- Enabling resolution may cause additional errors to occur due to
119- -- insufficient permissions, broken links, or symlink loops. Such errors
120- -- can be ignored or handled using the appropriate options.
121- --
122- -- The default is 'False'.
123- --
124- -- On Windows this option does nothing as of now, symlinks are not followed to
125- -- determine the type.
126- followSymlinks :: Bool -> ReadOptions -> ReadOptions
127- followSymlinks x opts = opts {_followSymlinks = x}
128-
129- -- | When the 'followSymlinks' option is enabled and a directory entry is a
130- -- symbolic link, we resolve it to determine the type of the symlink target.
131- -- This option controls the behavior when encountering symlink loop errors
132- -- during resolution.
133- --
134- -- When set to 'True', symlink loop errors are ignored, and the type is
135- -- reported as not a directory. When set to 'False', the directory read
136- -- operation fails with an error.
137- --
138- -- The default is 'False'.
139- ignoreSymlinkLoops :: Bool -> ReadOptions -> ReadOptions
140- ignoreSymlinkLoops x opts = opts {_ignoreELOOP = x}
141-
142- -- | When the 'followSymlinks' option is enabled and a directory entry is a
143- -- symbolic link, we resolve it to determine the type of the symlink target.
144- -- This option controls the behavior when encountering broken symlink errors
145- -- during resolution.
146- --
147- -- When set to 'True', broken symlink errors are ignored, and the type is
148- -- reported as not a directory. When set to 'False', the directory read
149- -- operation fails with an error.
150- --
151- -- The default is 'False'.
152- ignoreMissing :: Bool -> ReadOptions -> ReadOptions
153- ignoreMissing x opts = opts {_ignoreENOENT = x}
154-
155- -- | When the 'followSymlinks' option is enabled and a directory entry is a
156- -- symbolic link, we resolve it to determine the type of the symlink target.
157- -- This option controls the behavior when encountering permission errors
158- -- during resolution.
159- --
160- -- When set to 'True', any permission errors are ignored, and the type is
161- -- reported as not a directory. When set to 'False', the directory read
162- -- operation fails with an error.
163- --
164- -- The default is 'False'.
165- ignoreInaccessible :: Bool -> ReadOptions -> ReadOptions
166- ignoreInaccessible x opts = opts {_ignoreEACCESS = x}
167-
168- -- NOTE: The defaultReadOptions emulate the behaviour of "find".
169- --
170- defaultReadOptions :: ReadOptions
171- defaultReadOptions =
172- ReadOptions
173- { _followSymlinks = False
174- , _ignoreELOOP = False
175- , _ignoreENOENT = False
176- , _ignoreEACCESS = False
177- }
178-
17977-- | Minimal read without any metadata.
18078{-# INLINE readScanWith_ #-}
18179readScanWith_ :: -- (MonadIO m, MonadCatch m) =>
0 commit comments