@@ -1,50 +0,0 @@
1−-- | Filesystem polling with an inotify backend. Works only on linux.
2−--
3−module Hakyll.Web.Preview.Poll
4− ( previewPoll
5− ) where
6−
7−import Control.Monad (forM_, when)
8−import Data.Set (Set)
9−import qualified Data.Set as S
10−import System.FilePath (takeDirectory, (</>))
11−import Data.List (isPrefixOf)
12−
13−import System.INotify
14−
15−import Hakyll.Core.Configuration
16−import Hakyll.Core.Resource
17−
18−-- | Calls the given callback when the directory tree changes
19−--
20−previewPoll :: HakyllConfiguration -- ^ Configuration
21− -> Set Resource -- ^ Resources to watch
22− -> IO () -- ^ Action called when something changes
23− -> IO () -- ^ Can block forever
24−previewPoll _ resources callback = do
25− -- Initialize inotify
26− inotify <- initINotify
27−
28− let -- A set of file paths
29− paths = S.map unResource resources
30−
31− -- A list of directories. Run it through a set so we have every
32− -- directory only once.
33− directories = S.toList $ S.map (notEmpty . takeDirectory) paths
34−
35− -- Problem: we can't add a watcher for "". So we make sure a directory
36− -- name is not empty
37− notEmpty "" = "."
38− notEmpty x = x
39−
40− -- Execute the callback when path is known
41− ifResource path =
42− let path' = if "./" `isPrefixOf` path then drop 2 path else path
43− in when (path' `S.member` paths) callback
44−
45− -- Add a watcher for every directory
46− forM_ directories $ \directory -> do
47− _ <- addWatch inotify [Modify] directory $ \e -> case e of
48− (Modified _ (Just p)) -> ifResource $ directory </> p
49− _ -> return ()
50− return ()