diff --git a/src/System/INotify.hsc b/src/System/INotify.hsc index 03f8ee1..2f4e423 100644 --- a/src/System/INotify.hsc +++ b/src/System/INotify.hsc @@ -26,6 +26,8 @@ module System.INotify , withINotify , addWatch , removeWatch + , eventFilePath + , eventSourceIsSelf , INotify , WatchDescriptor , Event(..) @@ -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