diff options
author | Simonas Kazlauskas <git@kazlauskas.me> | 2013-03-30 18:38:31 +0200 |
---|---|---|
committer | Simonas Kazlauskas <git@kazlauskas.me> | 2013-03-30 18:39:02 +0200 |
commit | bcc0ef828ec6f0abd8f397e6c04335e2c37256c9 (patch) | |
tree | 4cac764d59d7d8b591ae7bbdd517f6b67c4625d5 | |
parent | 7677bb4a775f7e0f6d1d88a5c0d37d5eb30d0213 (diff) | |
download | hakyll-bcc0ef828ec6f0abd8f397e6c04335e2c37256c9.tar.gz |
Prefer relative directories instead of absolute
This allows us to fully utilise shouldIgnoreFile
-rw-r--r-- | src/Hakyll/Preview/Poll.hs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/Hakyll/Preview/Poll.hs b/src/Hakyll/Preview/Poll.hs index ec53e85..9f7a505 100644 --- a/src/Hakyll/Preview/Poll.hs +++ b/src/Hakyll/Preview/Poll.hs @@ -4,12 +4,11 @@ module Hakyll.Preview.Poll -------------------------------------------------------------------------------- import Control.Monad (void) -import Data.List (isPrefixOf) import Filesystem.Path.CurrentOS (decodeString, encodeString) -import System.Directory (canonicalizePath) +import System.Directory (getCurrentDirectory) +import System.FilePath (makeRelative) import System.FSNotify (startManagerConf, watchTree, Event(..), WatchConfig(..)) -import System.IO.Error (catchIOError) -------------------------------------------------------------------------------- import Hakyll.Core.Configuration @@ -24,21 +23,20 @@ previewPoll :: Configuration -- ^ Configuration previewPoll conf update = do _ <- update manager <- startManagerConf (Debounce 0.1) - ignore <- mapM getPath [destinationDirectory, storeDirectory, tmpDirectory] - watchTree manager path (predicate ignore) (\_ -> void update) + wDir <- getCurrentDirectory + watchTree manager path (predicate wDir) (\_ -> void update) where path = decodeString $ providerDirectory conf - getPath fn = catchIOError (canonicalizePath $ fn conf) - (const $ return $ fn conf) - predicate ignore evt + predicate wDir evt | isRemove evt = False - | any (flip isPrefixOf $ eventPath evt) ignore == True = False - | otherwise = not $ shouldIgnoreFile conf (eventPath evt) + | otherwise = not $ shouldIgnoreFile conf (relativeEventPath wDir evt) -eventPath :: Event -> FilePath -eventPath (Added p _) = encodeString p -eventPath (Modified p _) = encodeString p -eventPath (Removed p _) = encodeString p +relativeEventPath :: FilePath -> Event -> FilePath +relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt + where + evtPath (Added p _) = p + evtPath (Modified p _) = p + evtPath (Removed p _) = p isRemove :: Event -> Bool isRemove (Removed _ _) = True |