synthesize RmChange when a directory is deleted

This gets directory renames closer to being fully detected.
There's close to no extra overhead to doing it this way.
This commit is contained in:
Joey Hess 2013-03-11 15:14:42 -04:00
parent c15023a8b4
commit f340fd324c
3 changed files with 26 additions and 13 deletions

View file

@ -80,7 +80,7 @@ waitChangeTime a = runEvery (Seconds 1) <~> do
changes <- getChanges
-- See if now's a good time to commit.
now <- liftIO getCurrentTime
case (shouldCommit now changes, lonelychange changes) of
case (shouldCommit now changes, possiblyrename changes) of
(True, False) -> a (changes, now)
(True, True) -> do
-- Wait for other, related changes to arrive.
@ -92,10 +92,13 @@ waitChangeTime a = runEvery (Seconds 1) <~> do
_ -> refill changes
where
{- Did we perhaps only get one of the AddChange and RmChange pair
- that make up a rename? -}
lonelychange [(PendingAddChange _ _)] = True
lonelychange [c] | isRmChange c = True
lonelychange _ = False
- that make up a file rename? Or some of the pairs that make up
- a directory rename?
-}
possiblyrename cs = all renamepart cs
renamepart (PendingAddChange _ _) = True
renamepart c = isRmChange c
isRmChange :: Change -> Bool
isRmChange (Change { changeInfo = i }) | i == RmChange = True

View file

@ -43,6 +43,7 @@ import Data.Bits.Utils
import Data.Typeable
import qualified Data.ByteString.Lazy as L
import qualified Control.Exception as E
import Data.Time.Clock
checkCanWatch :: Annex ()
checkCanWatch
@ -251,17 +252,26 @@ onDel file _ = do
{- A directory has been deleted, or moved, so tell git to remove anything
- that was inside it from its cache. Since it could reappear at any time,
- use --cached to only delete it from the index.
- use --cached to only delete it from the index.
-
- Note: This could use unstageFile, but would need to run another git
- command to get the recursive list of files in the directory, so rm is
- just as good. -}
- This queues up a lot of RmChanges, which assists the Committer in
- pairing up renamed files when the directory was renamed. -}
onDelDir :: Handler
onDelDir dir _ = do
debug ["directory deleted", dir]
liftAnnex $ Annex.Queue.addCommand "rm"
[Params "--quiet -r --cached --ignore-unmatch --"] [dir]
madeChange dir RmDirChange
(fs, clean) <- liftAnnex $ inRepo $ LsFiles.deleted [dir]
liftAnnex $ forM_ fs $ \f -> Annex.Queue.addUpdateIndex =<<
inRepo (Git.UpdateIndex.unstageFile f)
-- Get the events queued up as fast as possible, so the
-- committer sees them all in one block.
now <- liftIO getCurrentTime
forM_ fs $ \f -> recordChange $ Change now f RmChange
void $ liftIO $ clean
liftAnnex $ Annex.Queue.flushWhenFull
noChange
{- Called when there's an error with inotify or kqueue. -}
onErr :: Handler

View file

@ -14,7 +14,7 @@ import Utility.TSet
import Data.Time.Clock
import Control.Concurrent.STM
data ChangeInfo = AddChange Key | LinkChange (Maybe Key) | RmChange | RmDirChange
data ChangeInfo = AddChange Key | LinkChange (Maybe Key) | RmChange
deriving (Show, Eq)
changeInfoKey :: ChangeInfo -> Maybe Key