summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Web/Preview/INotify.hs15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/Hakyll/Web/Preview/INotify.hs b/src/Hakyll/Web/Preview/INotify.hs
index 5bee981..9af6def 100644
--- a/src/Hakyll/Web/Preview/INotify.hs
+++ b/src/Hakyll/Web/Preview/INotify.hs
@@ -7,7 +7,7 @@ module Hakyll.Web.Preview.INotify
import Control.Monad (forM_, when)
import Data.Set (Set)
import qualified Data.Set as S
-import System.FilePath (takeDirectory)
+import System.FilePath (takeDirectory, (</>))
import System.INotify
@@ -28,10 +28,12 @@ previewPoll _ resources callback = do
let -- A set of file paths
paths = S.map (toFilePath . unResource) resources
- -- A list of directories
+ -- A list of directories. Run it through a set so we have every
+ -- directory only once.
directories = S.toList $ S.map (notEmpty . takeDirectory) paths
- -- Make sure a directory name is not empty
+ -- Problem: we can't add a watcher for "". So we make sure a directory
+ -- name is not empty
notEmpty "" = "."
notEmpty x = x
@@ -43,10 +45,7 @@ previewPoll _ resources callback = do
-- Add a watcher for every directory
forM_ directories $ \directory -> do
putStrLn $ "Adding watch for " ++ directory
- _ <- addWatch inotify interesting directory $ \e -> case e of
- (Modified _ (Just p)) -> ifResource p
+ _ <- addWatch inotify [Modify] directory $ \e -> case e of
+ (Modified _ (Just p)) -> ifResource $ directory </> p
_ -> return ()
return ()
- where
- -- Interesting events
- interesting = [Modify]