Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
dist-newstyle/
.stack-work/
6 changes: 3 additions & 3 deletions kqueue.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Library
Hs-Source-Dirs: src
Exposed-modules: System.KQueue
System.KQueue.HighLevel
Build-depends: base >= 4.0 && < 4.15
Build-depends: base >= 4.0 && < 4.19
, directory >= 1.0 && < 1.4
, filepath >= 1.1 && < 1.5
, mtl >= 1.1 && < 2.3
, mtl >= 1.1 && < 2.4
, time >= 1.1 && < 1.12
, unix >= 2.3 && < 2.8
, unix >= 2.3 && < 2.9
Build-tools: c2hs
GHC-Options: -Wall
Default-language: Haskell2010
Expand Down
11 changes: 6 additions & 5 deletions src/System/KQueue/HighLevel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module System.KQueue.HighLevel
) where

import Control.Concurrent (ThreadId, forkIO, killThread)
import Control.Monad.State (StateT, evalStateT, forever, get, liftIO, liftM, put, when)
import Control.Monad (forever, when, liftM)
import Control.Monad.State (StateT, evalStateT, get, liftIO, put)
import Data.List (intersect)
import Foreign.Ptr (nullPtr)
import System.Directory (canonicalizePath, doesFileExist)
Expand Down Expand Up @@ -45,7 +46,7 @@ stopWatching (Watcher tid) = killThread tid
watchDirectoryForFile :: KQueue -> FilePath -> FilePath -> (EventType -> IO ()) -> IO ()
watchDirectoryForFile kq dir file callback =
do -- Event structures for the directory and file to monitor
dfd <- openFd dir ReadOnly Nothing defaultFileFlags
dfd <- openFd dir ReadOnly defaultFileFlags
let dirEvent = KEvent
{ ident = fromIntegral dfd
, evfilter = EvfiltVnode
Expand All @@ -67,7 +68,7 @@ watchDirectoryForFile kq dir file callback =
exists <- doesFileExist file
mFd <-
if exists
then Just `liftM` openFd file ReadOnly Nothing defaultFileFlags
then Just `liftM` openFd file ReadOnly defaultFileFlags
else return Nothing
-- Add the event(s) to the queue.
let eventsToAdd = dirEvent : maybe [] (return . mkFileEvent) mFd
Expand Down Expand Up @@ -109,7 +110,7 @@ monitorChangesIO kq dirEvent mkFileEvent callback file mFd =
(True, Nothing) -> -- The file was created.
do callback Created
-- Start monitoring it.
fd <- openFd file ReadOnly Nothing defaultFileFlags
fd <- openFd file ReadOnly defaultFileFlags
_ <- kevent kq [setFlag EvAdd (mkFileEvent fd)] 0 Nothing
return (Just fd)
(False, Just fd) -> -- The file was deleted.
Expand All @@ -128,7 +129,7 @@ monitorChangesIO kq dirEvent mkFileEvent callback file mFd =
-- Remove the event on the old file.
_ <- kevent kq [setFlag EvDelete (mkFileEvent fd)] 0 Nothing
-- Add the event on the new file.
newFd <- openFd file ReadOnly Nothing defaultFileFlags
newFd <- openFd file ReadOnly defaultFileFlags
_ <- kevent kq [setFlag EvAdd (mkFileEvent newFd)] 0 Nothing
return (Just newFd)
-- A directory event, but not on the file we're interested
Expand Down