on master help sign in
Fix inappropriate type (Not a directory) error

In Linux module for File paths in recursive mode.

commit842d0ca9e74dcf2c9c70313ca952dec843cc70c5 authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateSat 27 Nov 2021, 16:52 (5 years ago) parentdd4774b
4 files changed+9−6
src/Streamly/Internal/FileSystem/Event/Linux.hs+3−1 src/Streamly/Internal/FileSystem/Event/Windows.hs+4−4 test/Streamly/Test/FileSystem/Event/Linux.hs+1−1 test/Streamly/Test/FileSystem/Event/Windows.hs+1
src/Streamly/Internal/FileSystem/Event/Linux.hs+3−1
@@ -193,6 +193,7 @@ import qualified Streamly.Internal.Data.Fold as FL
193193import qualified Streamly.Internal.Data.Parser as PR
194194import qualified Streamly.Internal.Data.Stream.IsStream as S
195195import qualified Streamly.Internal.FileSystem.Dir as Dir
196+import qualified System.Directory as Dir
196197import qualified Streamly.Internal.FileSystem.Handle as FH
197198import qualified Streamly.Internal.Unicode.Stream as U
198199
@@ -745,7 +746,8 @@ addToWatch cfg@Config{..} watch0@(Watch handle wdMap) root0 path0 = do
745746 --
746747 -- XXX toDirs currently uses paths as String, we need to convert it
747748 -- to "/" separated by byte arrays.
748− when watchRec $ do
749+ pathIsDir <- Dir.doesDirectoryExist $ utf8ToString absPath
750+ when (watchRec && pathIsDir) $ do
749751 S.mapM_ (\p -> addToWatch cfg watch0 root (appendPaths path p))
750752 $ S.mapM toUtf8
751753 $ Dir.toDirs $ utf8ToString absPath
src/Streamly/Internal/FileSystem/Event/Windows.hs+4−4
@@ -12,13 +12,13 @@
1212--
1313-- =Overview
1414--
15−-- Use 'watchTrees'or 'watchPaths' with a list of file system paths you want to
16−-- watch as argument. It returns a stream of 'Event' representing the file
17−-- system events occurring under the watched paths.
15+-- Use 'watchRecursive'or 'watch' with a list of file system dir paths you
16+-- want to watch as argument. It returns a stream of 'Event' representing the
17+-- file system events occurring under the watched paths.
1818--
1919-- @
2020-- {-\# LANGUAGE MagicHash #-}
21−-- Stream.mapM_ (putStrLn . 'showEvent') $ 'watchTrees' [Array.fromCString\# "path"#]
21+-- Stream.mapM_ (putStrLn . 'showEvent') $ 'watchRecursive' [Array.fromCString\# "path"#]
2222-- @
2323--
2424-- 'Event' is an opaque type. Accessor functions (e.g. 'showEvent' above)
test/Streamly/Test/FileSystem/Event/Linux.hs+1−1
@@ -149,4 +149,4 @@ main = do
149149 runRec SymLinkOrigPath recSymTests
150150 -- XXX This fails with exceptions, ideally it should work the same as in
151151 -- non-recursive mode
152− -- runRec FileType fileRootTests
152+ runRec FileType fileRootTests
test/Streamly/Test/FileSystem/Event/Windows.hs+1
@@ -38,6 +38,7 @@ main = do
3838 -- TODO create/modify/delete/move with root path as a regular file, copy
3939 -- from macOS tests
4040 -- run FileType fileRootTests
41+ -- Windows watch events only supports dir path as root.
4142
4243 let recTests =
4344 [ dirCreateWithParent "subdir\\dir"