summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-23 10:11:55 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-23 10:11:55 +0100
commit5abc3d87e234c2f92b6c5481200d1f813ca2ce6f (patch)
tree422fd79a23bb2af298ccf223c8a3b9709426044a /src
parent371c28cb1a7976740f104b0737b6b9c37c08b72f (diff)
downloadhakyll-5abc3d87e234c2f92b6c5481200d1f813ca2ce6f.tar.gz
Add cabal flag for inotify
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Main.hs2
-rw-r--r--src/Hakyll/Web/Preview/INotify.hs52
-rw-r--r--src/Hakyll/Web/Preview/Interval.hs36
3 files changed, 1 insertions, 89 deletions
diff --git a/src/Hakyll/Main.hs b/src/Hakyll/Main.hs
index 13ec0dd..a44d9fa 100644
--- a/src/Hakyll/Main.hs
+++ b/src/Hakyll/Main.hs
@@ -14,7 +14,7 @@ import Hakyll.Core.Configuration
import Hakyll.Core.Run
import Hakyll.Core.Rules
import Hakyll.Core.Rules.Internal
-import Hakyll.Web.Preview.INotify
+import Hakyll.Web.Preview.Poll
import Hakyll.Web.Preview.Server
-- | This usualy is the function with which the user runs the hakyll compiler
diff --git a/src/Hakyll/Web/Preview/INotify.hs b/src/Hakyll/Web/Preview/INotify.hs
deleted file mode 100644
index e21b767..0000000
--- a/src/Hakyll/Web/Preview/INotify.hs
+++ /dev/null
@@ -1,52 +0,0 @@
--- | Filesystem polling with an inotify backend. Works only on linux.
---
-module Hakyll.Web.Preview.INotify
- ( previewPoll
- ) where
-
-import Control.Monad (forM_, when)
-import Data.Set (Set)
-import qualified Data.Set as S
-import System.FilePath (takeDirectory, (</>))
-import Data.List (isPrefixOf)
-
-import System.INotify
-
-import Hakyll.Core.Configuration
-import Hakyll.Core.ResourceProvider
-import Hakyll.Core.Identifier
-
--- | Calls the given callback when the directory tree changes
---
-previewPoll :: HakyllConfiguration -- ^ Configuration
- -> Set Resource -- ^ Resources to watch
- -> IO () -- ^ Action called when something changes
- -> IO () -- ^ Can block forever
-previewPoll _ resources callback = do
- -- Initialize inotify
- inotify <- initINotify
-
- let -- A set of file paths
- paths = S.map (toFilePath . unResource) resources
-
- -- A list of directories. Run it through a set so we have every
- -- directory only once.
- directories = S.toList $ S.map (notEmpty . takeDirectory) paths
-
- -- Problem: we can't add a watcher for "". So we make sure a directory
- -- name is not empty
- notEmpty "" = "."
- notEmpty x = x
-
- -- Execute the callback when path is known
- ifResource path =
- let path' = if "./" `isPrefixOf` path then drop 2 path else path
- in when (path' `S.member` paths) callback
-
- -- Add a watcher for every directory
- forM_ directories $ \directory -> do
- putStrLn $ "Adding watch for " ++ directory
- _ <- addWatch inotify [Modify] directory $ \e -> case e of
- (Modified _ (Just p)) -> ifResource $ directory </> p
- _ -> return ()
- return ()
diff --git a/src/Hakyll/Web/Preview/Interval.hs b/src/Hakyll/Web/Preview/Interval.hs
deleted file mode 100644
index 5ab90e5..0000000
--- a/src/Hakyll/Web/Preview/Interval.hs
+++ /dev/null
@@ -1,36 +0,0 @@
--- | Interval-based implementation of preview polling, for the platforms which
--- are not supported by inotify.
---
-module Hakyll.Web.Preview.Interval
- ( previewPoll
- ) where
-
-import Control.Applicative ((<$>))
-import Control.Concurrent (threadDelay)
-import Control.Monad (when)
-import System.Time (getClockTime)
-import Data.Set (Set)
-import qualified Data.Set as S
-import System.Directory (getModificationTime)
-
-import Hakyll.Core.Configuration
-import Hakyll.Core.Identifier
-import Hakyll.Core.ResourceProvider
-
--- | A preview thread that periodically recompiles the site.
---
-previewPoll :: HakyllConfiguration -- ^ Configuration
- -> Set Resource -- ^ Resources to watch
- -> IO () -- ^ Action called when something changes
- -> IO () -- ^ Can block forever
-previewPoll _ resources callback = do
- let files = map (toFilePath . unResource) $ S.toList resources
- time <- getClockTime
- loop files time
- where
- delay = 1000000
- loop files time = do
- threadDelay delay
- modified <- any (time <) <$> mapM getModificationTime files
- when modified callback
- loop files =<< getClockTime