summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@oberon.tam-lin.net>2012-12-27 14:46:18 -0500
committerGravatar Joey Hess <joey@kitenet.net>2012-12-27 15:46:37 -0400
commit4ad854692bc49257055e7258196b05adbd4a0c85 (patch)
treed0600d168aed8b6c6df6707e2d3eb361131f5efa
parent8f7f2976096db7ae873116f85da6445df9fe3ae6 (diff)
startup scan for FSEvents
-rw-r--r--Utility/FSEvents.hs23
1 files changed, 22 insertions, 1 deletions
diff --git a/Utility/FSEvents.hs b/Utility/FSEvents.hs
index 8a8f890eb..8fd676d9e 100644
--- a/Utility/FSEvents.hs
+++ b/Utility/FSEvents.hs
@@ -18,6 +18,7 @@ watchDir :: FilePath -> (FilePath -> Bool) -> WatchHooks -> IO EventStream
watchDir dir ignored hooks = do
unlessM fileLevelEventsSupported $
error "Need at least OSX 10.7.0 for file-level FSEvents"
+ scan dir
eventStreamCreate [dir] 1.0 True False True handle
where
handle evt
@@ -52,9 +53,29 @@ watchDir dir ignored hooks = do
ms <- getstatus $ eventPath evt
runhook modifyHook ms
where
- getstatus = catchMaybeIO . getSymbolicLinkStatus
hasflag f = eventFlags evt .&. f /= 0
runhook h s = maybe noop (\a -> a (eventPath evt) s) (h hooks)
+
+ scan d = unless (ignoredPath ignored d) $
+ mapM_ go =<< dirContentsRecursive d
+ where
+ go f
+ | ignoredPath ignored f = noop
+ | otherwise = do
+ ms <- getstatus f
+ case ms of
+ Nothing -> noop
+ Just s
+ | Files.isSymbolicLink s ->
+ runhook addSymlinkHook ms
+ | Files.isRegularFile s ->
+ runhook addHook ms
+ | otherwise ->
+ noop
+ where
+ runhook h s = maybe noop (\a -> a f s) (h hooks)
+
+ getstatus = catchMaybeIO . getSymbolicLinkStatus
{- Check each component of the path to see if it's ignored. -}
ignoredPath :: (FilePath -> Bool) -> FilePath -> Bool