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.
This commit is contained in:
parent
eab3872d91
commit
23dbff4b43
2 changed files with 86 additions and 47 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue