on master help sign in
Prefer relative directories instead of absolute

This allows us to fully utilise shouldIgnoreFile

commitbcc0ef828ec6f0abd8f397e6c04335e2c37256c9 authorSimonas Kazlauskas <git@kazlauskas.me> dateSat 30 Mar 2013, 18:38 (14 years ago) parent7677bb4
1 file changed+12−14
src/Hakyll/Preview/Poll.hs+12−14
src/Hakyll/Preview/Poll.hs+12−14
@@ -4,12 +4,11 @@ module Hakyll.Preview.Poll
44
55--------------------------------------------------------------------------------
66import Control.Monad (void)
7−import Data.List (isPrefixOf)
87import Filesystem.Path.CurrentOS (decodeString, encodeString)
9−import System.Directory (canonicalizePath)
8+import System.Directory (getCurrentDirectory)
9+import System.FilePath (makeRelative)
1010import System.FSNotify (startManagerConf, watchTree,
1111 Event(..), WatchConfig(..))
12−import System.IO.Error (catchIOError)
1312
1413--------------------------------------------------------------------------------
1514import Hakyll.Core.Configuration
@@ -24,21 +23,20 @@ previewPoll :: Configuration -- ^ Configuration
2423previewPoll conf update = do
2524 _ <- update
2625 manager <- startManagerConf (Debounce 0.1)
27− ignore <- mapM getPath [destinationDirectory, storeDirectory, tmpDirectory]
28− watchTree manager path (predicate ignore) (\_ -> void update)
26+ wDir <- getCurrentDirectory
27+ watchTree manager path (predicate wDir) (\_ -> void update)
2928 where
3029 path = decodeString $ providerDirectory conf
31− getPath fn = catchIOError (canonicalizePath $ fn conf)
32− (const $ return $ fn conf)
33− predicate ignore evt
30+ predicate wDir evt
3431 | isRemove evt = False
35− | any (flip isPrefixOf $ eventPath evt) ignore == True = False
36− | otherwise = not $ shouldIgnoreFile conf (eventPath evt)
32+ | otherwise = not $ shouldIgnoreFile conf (relativeEventPath wDir evt)
3733
38−eventPath :: Event -> FilePath
39−eventPath (Added p _) = encodeString p
40−eventPath (Modified p _) = encodeString p
41−eventPath (Removed p _) = encodeString p
34+relativeEventPath :: FilePath -> Event -> FilePath
35+relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt
36+ where
37+ evtPath (Added p _) = p
38+ evtPath (Modified p _) = p
39+ evtPath (Removed p _) = p
4240
4341isRemove :: Event -> Bool
4442isRemove (Removed _ _) = True