summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-19 10:39:29 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-19 10:39:29 +0100
commitb89aad6178b151a859469a3ae5c6ed4e6f57cad6 (patch)
tree281b0750f044a49ed88f5c2afa7608f264fa5f42
parent4c75843c81d83980ff5757520b2e3e93ad9084ca (diff)
downloadhakyll-b89aad6178b151a859469a3ae5c6ed4e6f57cad6.tar.gz
Include the directory in the path
-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]