Merge branch 'master' into type-safe-identifiers

This commit is contained in:
Jasper Van der Jeugt 2011-05-28 10:43:27 +02:00
commit 01a8ab20d6
4 changed files with 1 additions and 76 deletions

View file

@ -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
--------

View file

@ -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.*,

View file

@ -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 ()

View file

@ -1,5 +1,4 @@
-- | Interval-based implementation of preview polling, for the platforms which
-- are not supported by inotify.
-- | Interval-based implementation of preview polling
--
module Hakyll.Web.Preview.Poll
( previewPoll