summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-04 13:22:56 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-04 13:22:56 -0400
commit23dbff4b4381628fab2827e693e8234243a63511 (patch)
tree6f8272b8b25abe0c6587f478a59095c4c963a8a1 /Command
parenteab3872d9145e7733cf69d4e8c696ff075081081 (diff)
add events for symlink creation and directory removal
Improved the inotify code, so it will also notice directory removal and symlink creation. In the watch code, optimised away a stat of a file that's being added, that's done by Command.Add.start. This is the reason symlink creation is handled separately from file creation, since during initial tree walk at startup, a stat was already done, and can be reused.
Diffstat (limited to 'Command')
-rw-r--r--Command/Watch.hs22
1 files changed, 18 insertions, 4 deletions
diff --git a/Command/Watch.hs b/Command/Watch.hs
index e0fa97ac5..a7553a677 100644
--- a/Command/Watch.hs
+++ b/Command/Watch.hs
@@ -29,12 +29,15 @@ start = notBareRepo $ do
showAction "scanning"
state <- Annex.getState id
next $ next $ liftIO $ withINotify $ \i -> do
- watchDir i notgit (Just $ run state onAdd) Nothing "."
+ let hook a = Just $ run state a
+ watchDir i "." (not . gitdir)
+ (hook onAdd) (hook onAddSymlink)
+ (hook onDel) (hook onDelDir)
putStrLn "(started)"
waitForTermination
return True
where
- notgit dir = takeFileName dir /= ".git"
+ gitdir dir = takeFileName dir /= ".git"
{- Inotify events are run in separate threads, and so each is a
- self-contained Annex monad. Exceptions by the handlers are ignored,
@@ -51,5 +54,16 @@ run startstate a f = do
_ <- shutdown True
return ()
-onAdd :: FilePath -> Annex Bool
-onAdd file = doCommand $ Add.start file
+onAdd :: FilePath -> Annex ()
+onAdd file = void $ doCommand $ do
+ showStart "add" file
+ next $ Add.perform file
+
+onAddSymlink :: FilePath -> Annex ()
+onAddSymlink link = liftIO $ print $ "add symlink " ++ link
+
+onDel :: FilePath -> Annex ()
+onDel file = liftIO $ print $ "del " ++ file
+
+onDelDir :: FilePath -> Annex ()
+onDelDir dir = liftIO $ print $ "del dir " ++ dir