plumb file status through to event handlers
The idea, not yet done, is to use this to detect when a file has an old change time, and avoid expensive restaging of the file. If git-annex watch keeps track of the last time it finished a full scan, then any symlink that is older than that time must have been scanned before, so need not be added. (Relying on moving, copying, etc of a file all updating its change time.) Anyway, this info is available for free since inotify already checks it, so it might as well make it available.
This commit is contained in:
parent
ab076b2e81
commit
12dbb9d1d0
2 changed files with 37 additions and 30 deletions
|
@ -68,7 +68,7 @@ import System.INotify
|
|||
|
||||
type ChangeChan = TChan Change
|
||||
|
||||
type Handler = FilePath -> Annex (Maybe Change)
|
||||
type Handler = FilePath -> Maybe FileStatus -> Annex (Maybe Change)
|
||||
|
||||
data Change = Change
|
||||
{ changeTime :: UTCTime
|
||||
|
@ -181,9 +181,9 @@ runChangeChan = atomically
|
|||
-
|
||||
- Exceptions are ignored, otherwise a whole watcher thread could be crashed.
|
||||
-}
|
||||
runHandler :: MVar Annex.AnnexState -> ChangeChan -> Handler -> FilePath -> IO ()
|
||||
runHandler st changechan handler file = void $ do
|
||||
r <- tryIO (runStateMVar st $ handler file)
|
||||
runHandler :: MVar Annex.AnnexState -> ChangeChan -> Handler -> FilePath -> Maybe FileStatus -> IO ()
|
||||
runHandler st changechan handler file filestatus = void $ do
|
||||
r <- tryIO (runStateMVar st $ handler file filestatus)
|
||||
case r of
|
||||
Left e -> print e
|
||||
Right Nothing -> noop
|
||||
|
@ -214,7 +214,7 @@ noChange = return Nothing
|
|||
- startup.
|
||||
-}
|
||||
onAdd :: Handler
|
||||
onAdd file = do
|
||||
onAdd file _filestatus = do
|
||||
ifM (Annex.getState Annex.fast)
|
||||
( go -- initial directory scan is complete
|
||||
, do -- expensive check done only during startup scan
|
||||
|
@ -243,7 +243,7 @@ onAdd file = do
|
|||
- already exist.
|
||||
-}
|
||||
onAddSymlink :: Handler
|
||||
onAddSymlink file = go =<< Backend.lookupFile file
|
||||
onAddSymlink file filestatus = go =<< Backend.lookupFile file
|
||||
where
|
||||
go Nothing = addlink =<< liftIO (readSymbolicLink file)
|
||||
go (Just (key, _)) = do
|
||||
|
@ -270,7 +270,7 @@ onAddSymlink file = go =<< Backend.lookupFile file
|
|||
madeChange file "link"
|
||||
|
||||
onDel :: Handler
|
||||
onDel file = do
|
||||
onDel file _filestatus = do
|
||||
Annex.Queue.addUpdateIndex =<<
|
||||
inRepo (Git.UpdateIndex.unstageFile file)
|
||||
madeChange file "rm"
|
||||
|
@ -283,14 +283,14 @@ onDel file = do
|
|||
- command to get the recursive list of files in the directory, so rm is
|
||||
- just as good. -}
|
||||
onDelDir :: Handler
|
||||
onDelDir dir = do
|
||||
onDelDir dir _filestatus = do
|
||||
Annex.Queue.addCommand "rm"
|
||||
[Params "--quiet -r --cached --ignore-unmatch --"] [dir]
|
||||
madeChange dir "rmdir"
|
||||
|
||||
{- Called when there's an error with inotify. -}
|
||||
onErr :: Handler
|
||||
onErr msg = do
|
||||
onErr msg _ = do
|
||||
warning msg
|
||||
return Nothing
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue