Skip to content

Commit

Permalink
Revert the Event module changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Oct 17, 2024
1 parent e0348e6 commit e11fded
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 124 deletions.
9 changes: 5 additions & 4 deletions src/Streamly/Internal/FileSystem/Event.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ module Streamly.Internal.FileSystem.Event
where

import Data.List.NonEmpty (NonEmpty)
import Data.Word (Word8)
import Streamly.Data.Array (Array)
import Streamly.Data.Stream (Stream)
import Streamly.FileSystem.Path (Path)

#if defined(CABAL_OS_DARWIN)
import Streamly.Internal.FileSystem.Event.Darwin (Event)
Expand Down Expand Up @@ -117,7 +118,7 @@ import qualified Streamly.Internal.FileSystem.Event.Windows as Event
--
-- /Pre-release/
--
watch :: NonEmpty Path -> Stream IO Event
watch :: NonEmpty (Array Word8) -> Stream IO Event
#if defined(CABAL_OS_DARWIN)
watch = Event.watchRecursive
#else
Expand All @@ -131,7 +132,7 @@ watch = Event.watch
--
-- /Pre-release/
--
_watchRecursive :: NonEmpty Path -> Stream IO Event
_watchRecursive :: NonEmpty (Array Word8) -> Stream IO Event
_watchRecursive = Event.watchRecursive

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -161,7 +162,7 @@ _watchRecursive = Event.watchRecursive
--
-- /Pre-release/
--
getAbsPath :: Event -> Path
getAbsPath :: Event -> Array Word8
getAbsPath = Event.getAbsPath

-- | Determine whether the event indicates creation of an object within the
Expand Down
29 changes: 15 additions & 14 deletions src/Streamly/Internal/FileSystem/Event/Darwin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ where
import Control.Concurrent (MVar, newMVar, takeMVar, putMVar)
import Control.Monad (when)
import Data.Bits ((.|.), (.&.), complement)
import Data.Functor.Identity (runIdentity)
import Data.List.NonEmpty (NonEmpty)
import Data.Word (Word8, Word32, Word64)
import Foreign.C.Types (CInt(..), CDouble(..), CSize(..), CUChar(..))
Expand All @@ -175,15 +176,15 @@ import Streamly.Internal.Data.Stream (Stream)
import Streamly.Internal.Data.Cont (contListMap)
import Streamly.Internal.Data.Parser (Parser)
import Streamly.Internal.Data.Array (Array(..))
import Streamly.Internal.FileSystem.Path (Path)
import System.IO (Handle, hClose)

import qualified Data.List.NonEmpty as NonEmpty
import qualified Streamly.Data.Fold as FL
import qualified Streamly.Internal.Data.Parser as PR
import qualified Streamly.Internal.Data.Stream as S
import qualified Streamly.Internal.Unicode.Stream as U
import qualified Streamly.Internal.FileSystem.Handle as FH
import qualified Streamly.Internal.Data.Array as A
import qualified Streamly.Internal.FileSystem.Path as Path

-------------------------------------------------------------------------------
-- Subscription to events
Expand Down Expand Up @@ -423,7 +424,7 @@ data Watch = Watch Handle (Ptr CWatch) (MVar Bool)
--
-- /Pre-release/
--
openWatch :: Config -> NonEmpty Path -> IO Watch
openWatch :: Config -> NonEmpty (Array Word8) -> IO Watch
openWatch Config{..} paths = do
-- XXX write a test case when path does not exist
-- XXX write a test case when there are no permissions
Expand All @@ -448,9 +449,9 @@ openWatch Config{..} paths = do

where

withPathName :: Path -> (PathName -> IO a) -> IO a
withPathName path act = do
A.unsafePinnedAsPtr (Path.toChunk path) $ \ptr byteLen ->
withPathName :: Array Word8 -> (PathName -> IO a) -> IO a
withPathName arr act = do
A.unsafePinnedAsPtr arr $ \ptr byteLen ->
let pname = PathName (castPtr ptr) (fromIntegral byteLen)
in act pname

Expand Down Expand Up @@ -479,8 +480,8 @@ closeWatch (Watch h watchPtr mvar) = do
data Event = Event
{ eventId :: Word64
, eventFlags :: Word32
, eventAbsPath :: Path
}
, eventAbsPath :: Array Word8
} deriving (Show, Ord, Eq)

-- XXX We can perhaps use parseD monad instance for fusing with parseMany? Need
-- to measure the perf.
Expand All @@ -499,7 +500,7 @@ readOneEvent = do
return $ Event
{ eventId = eid
, eventFlags = fromIntegral eflags
, eventAbsPath = Path.unsafeFromChunk path
, eventAbsPath = path
}

watchToStream :: Watch -> Stream IO Event
Expand Down Expand Up @@ -558,7 +559,7 @@ watchToStream (Watch handle _ _) =
-- /Pre-release/
--
watchWith ::
(Config -> Config) -> NonEmpty Path -> Stream IO Event
(Config -> Config) -> NonEmpty (Array Word8) -> Stream IO Event
watchWith f paths = S.bracketIO before after watchToStream

where
Expand All @@ -570,14 +571,14 @@ watchWith f paths = S.bracketIO before after watchToStream
--
-- >>> watchRecursive = watchWith id
--
watchRecursive :: NonEmpty Path -> Stream IO Event
watchRecursive :: NonEmpty (Array Word8) -> Stream IO Event
watchRecursive = watchWith id

-- | Same as 'watchWith' using defaultConfig and non-recursive mode.
--
-- /Unimplemented/
--
watch :: NonEmpty Path -> Stream IO Event
watch :: NonEmpty (Array Word8) -> Stream IO Event
watch _paths = undefined

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -616,7 +617,7 @@ isEventIdWrapped = getFlag kFSEventStreamEventFlagEventIdsWrapped
--
-- /Pre-release/
--
getAbsPath :: Event -> Path
getAbsPath :: Event -> Array Word8
getAbsPath Event{..} = eventAbsPath

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -1035,7 +1036,7 @@ isLastHardLink = getFlag kFSEventStreamEventFlagItemIsLastHardlink
-- | Convert an 'Event' record to a String representation.
showEvent :: Event -> String
showEvent ev@Event{..} =
let path = Path.toString eventAbsPath
let path = runIdentity $ S.fold FL.toList $ U.decodeUtf8' $ A.read eventAbsPath
in "--------------------------"
++ "\nId = " ++ show eventId
++ "\nPath = " ++ show path
Expand Down
Loading

0 comments on commit e11fded

Please sign in to comment.