From b80ba8fe83220d373e639be363143cbbfd907081 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 27 May 2011 21:04:19 +0200 Subject: Syntax error in cabal file --- hakyll.cabal | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hakyll.cabal b/hakyll.cabal index 441aaee..7120646 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -38,11 +38,11 @@ library ghc-options: -Wall hs-source-dirs: src - if flag(inotify) - hs-source-dirs: src-inotify - build-depends: hinotify >= 0.3 - else - hs-source-dirs: src-interval +-- if flag(inotify) +-- hs-source-dirs: src-inotify +-- build-depends: hinotify >= 0.3 +-- else +-- hs-source-dirs: src-interval build-depends: base >= 4 && < 5, filepath == 1.*, -- cgit v1.2.3 From 6ab59438123d00b02b5a04235102df7af2926cd4 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 28 May 2011 12:41:37 +0200 Subject: Remove inotify bindings for now --- examples/hakyll/tutorial.markdown | 10 ------- hakyll.cabal | 14 --------- src-inotify/Hakyll/Web/Preview/Poll.hs | 50 --------------------------------- src-interval/Hakyll/Web/Preview/Poll.hs | 35 ----------------------- src/Hakyll/Web/Preview/Poll.hs | 34 ++++++++++++++++++++++ 5 files changed, 34 insertions(+), 109 deletions(-) delete mode 100644 src-inotify/Hakyll/Web/Preview/Poll.hs delete mode 100644 src-interval/Hakyll/Web/Preview/Poll.hs create mode 100644 src/Hakyll/Web/Preview/Poll.hs diff --git a/examples/hakyll/tutorial.markdown b/examples/hakyll/tutorial.markdown index 150e881..838edf5 100644 --- a/examples/hakyll/tutorial.markdown +++ b/examples/hakyll/tutorial.markdown @@ -262,16 +262,6 @@ this can generate more traffic than necessary, since it is possible that some files were not actually modified. If you use `rsync`, you can counter this using the `--checksum` option. -### Using inotify for the preview server - -Hakyll is able to use [inotify] to power the preview server. This is generally -faster and uses less resources than the default. However, [inotify] is only -supported on linux systems. You can enable the bindings using: - - [jasper@phoenix] cabal install -finotify hakyll - -[inotify]: http://inotify.aiken.cz/ - Problems -------- diff --git a/hakyll.cabal b/hakyll.cabal index 7120646..b8ff57c 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -26,24 +26,10 @@ source-repository head type: git location: git://github.com/jaspervdj/hakyll.git --- Disabled while inotify is broken with GHC 7. If you're interested in fixing, --- contact me! --- --- flag inotify --- description: Use the inotify bindings for the preview server. Better, --- but only works on Linux. --- default: False - library ghc-options: -Wall hs-source-dirs: src --- if flag(inotify) --- hs-source-dirs: src-inotify --- build-depends: hinotify >= 0.3 --- else --- hs-source-dirs: src-interval - build-depends: base >= 4 && < 5, filepath == 1.*, directory == 1.*, diff --git a/src-inotify/Hakyll/Web/Preview/Poll.hs b/src-inotify/Hakyll/Web/Preview/Poll.hs deleted file mode 100644 index 0c27f32..0000000 --- a/src-inotify/Hakyll/Web/Preview/Poll.hs +++ /dev/null @@ -1,50 +0,0 @@ --- | Filesystem polling with an inotify backend. Works only on linux. --- -module Hakyll.Web.Preview.Poll - ( 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.Resource - --- | 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 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 - _ <- addWatch inotify [Modify] directory $ \e -> case e of - (Modified _ (Just p)) -> ifResource $ directory p - _ -> return () - return () diff --git a/src-interval/Hakyll/Web/Preview/Poll.hs b/src-interval/Hakyll/Web/Preview/Poll.hs deleted file mode 100644 index 68ea8d4..0000000 --- a/src-interval/Hakyll/Web/Preview/Poll.hs +++ /dev/null @@ -1,35 +0,0 @@ --- | Interval-based implementation of preview polling, for the platforms which --- are not supported by inotify. --- -module Hakyll.Web.Preview.Poll - ( previewPoll - ) where - -import Control.Applicative ((<$>)) -import Control.Concurrent (threadDelay) -import Control.Monad (filterM) -import System.Time (getClockTime) -import System.Directory (getModificationTime, doesFileExist) - -import Hakyll.Core.Configuration - --- | A preview thread that periodically recompiles the site. --- -previewPoll :: HakyllConfiguration -- ^ Configuration - -> IO [FilePath] -- ^ Updating action - -> IO () -- ^ Can block forever -previewPoll _ update = do - time <- getClockTime - loop time =<< update - where - delay = 1000000 - loop time files = do - threadDelay delay - files' <- filterM doesFileExist files - filesTime <- case files' of - [] -> return time - _ -> maximum <$> mapM getModificationTime files' - - if filesTime > time || files' /= files - then loop filesTime =<< update - else loop time files' diff --git a/src/Hakyll/Web/Preview/Poll.hs b/src/Hakyll/Web/Preview/Poll.hs new file mode 100644 index 0000000..83ec54a --- /dev/null +++ b/src/Hakyll/Web/Preview/Poll.hs @@ -0,0 +1,34 @@ +-- | Interval-based implementation of preview polling +-- +module Hakyll.Web.Preview.Poll + ( previewPoll + ) where + +import Control.Applicative ((<$>)) +import Control.Concurrent (threadDelay) +import Control.Monad (filterM) +import System.Time (getClockTime) +import System.Directory (getModificationTime, doesFileExist) + +import Hakyll.Core.Configuration + +-- | A preview thread that periodically recompiles the site. +-- +previewPoll :: HakyllConfiguration -- ^ Configuration + -> IO [FilePath] -- ^ Updating action + -> IO () -- ^ Can block forever +previewPoll _ update = do + time <- getClockTime + loop time =<< update + where + delay = 1000000 + loop time files = do + threadDelay delay + files' <- filterM doesFileExist files + filesTime <- case files' of + [] -> return time + _ -> maximum <$> mapM getModificationTime files' + + if filesTime > time || files' /= files + then loop filesTime =<< update + else loop time files' -- cgit v1.2.3