on master help sign in
Prefer relative directories instead of absolute
bcc0ef8Simonas Kazlauskas
src/Hakyll/Preview/Poll.hs+12−14
@@ -4,12 +4,11 @@ module Hakyll.Preview.Poll
4
4
5--------------------------------------------------------------------------------
5--------------------------------------------------------------------------------
6import Control.Monad (void)
6import Control.Monad (void)
7−import Data.List (isPrefixOf)
8import Filesystem.Path.CurrentOS (decodeString, encodeString)
7import Filesystem.Path.CurrentOS (decodeString, encodeString)
9−import System.Directory (canonicalizePath)
8+import System.Directory (getCurrentDirectory)
9+import System.FilePath (makeRelative)
10import System.FSNotify (startManagerConf, watchTree,
10import System.FSNotify (startManagerConf, watchTree,
11 Event(..), WatchConfig(..))
11 Event(..), WatchConfig(..))
12−import System.IO.Error (catchIOError)
13
12
14--------------------------------------------------------------------------------
13--------------------------------------------------------------------------------
15import Hakyll.Core.Configuration
14import Hakyll.Core.Configuration
@@ -24,21 +23,20 @@ previewPoll :: Configuration -- ^ Configuration
24previewPoll conf update = do
23previewPoll conf update = do
25 _ <- update
24 _ <- update
26 manager <- startManagerConf (Debounce 0.1)
25 manager <- startManagerConf (Debounce 0.1)
27− ignore <- mapM getPath [destinationDirectory, storeDirectory, tmpDirectory]
26+ wDir <- getCurrentDirectory
28− watchTree manager path (predicate ignore) (\_ -> void update)
27+ watchTree manager path (predicate wDir) (\_ -> void update)
29 where
28 where
30 path = decodeString $ providerDirectory conf
29 path = decodeString $ providerDirectory conf
31− getPath fn = catchIOError (canonicalizePath $ fn conf)
32− (const $ return $ fn conf)
33− predicate ignore evt
30+ predicate wDir evt
34 | isRemove evt = False
31 | 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)
37
33
38−eventPath :: Event -> FilePath
34+relativeEventPath :: FilePath -> Event -> FilePath
39−eventPath (Added p _) = encodeString p
35+relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt
36+ where
37+ evtPath (Added p _) = p
40−eventPath (Modified p _) = encodeString p
38+ evtPath (Modified p _) = p
41−eventPath (Removed p _) = encodeString p
39+ evtPath (Removed p _) = p
42
40
43isRemove :: Event -> Bool
41isRemove :: Event -> Bool
44isRemove (Removed _ _) = True
42isRemove (Removed _ _) = True