Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/System/INotify.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module System.INotify
, withINotify
, addWatch
, removeWatch
, eventFilePath
, eventSourceIsSelf
, INotify
, WatchDescriptor
, Event(..)
Expand Down Expand Up @@ -139,6 +141,40 @@ data Event =
| Unknown FDEvent
deriving (Eq, Show)

-- | The file path that generated an event.
--
-- The value is @Nothing@ when no file path generated the event
-- (e.g. @QOverflow@) or if the event source is self (a path for which a
-- watch was explicitly added).
eventFilePath :: Event -> Maybe RawFilePath
eventFilePath event = case event of
Accessed _ mfp -> mfp
Modified _ mfp -> mfp
Attributes _ mfp -> mfp
Closed _ mfp _ -> mfp
Opened _ mfp -> mfp
MovedOut _ fp _ -> Just fp
MovedIn _ fp _ -> Just fp
Created _ fp -> Just fp
Deleted _ fp -> Just fp
_ -> Nothing

-- | Whether the source of the event is a root @WatchDescriptor@.
--
-- For example if there is watch added for @dir/@, watching for @DeleteSelf@
-- and @Create@ event varieties, then:
--
-- * for the event generated by creating the file @dir/some_file@,
-- @eventSourceIsSelf event == False@.
-- * for the event generated by deleting @dir/@,
-- @eventSourceIsSelf event == True@
eventSourceIsSelf :: Event -> Bool
eventSourceIsSelf event = case event of
MovedSelf _ -> True
DeletedSelf -> True
Unmounted -> True
_ -> False

data EventVariety
= Access
| Modify
Expand Down