summaryrefslogtreecommitdiff
path: root/Assistant/Threads/Watcher.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-11 15:14:42 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-11 15:14:42 -0400
commitb2f04c1ed094aec6f734103d50077c48f3aad2a9 (patch)
tree064012fec3e955f1422a6b05ad075894ea6c755b /Assistant/Threads/Watcher.hs
parentee98604d9463da1abadd0a9490f90a8bce358279 (diff)
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.
Diffstat (limited to 'Assistant/Threads/Watcher.hs')
-rw-r--r--Assistant/Threads/Watcher.hs24
1 files changed, 17 insertions, 7 deletions
diff --git a/Assistant/Threads/Watcher.hs b/Assistant/Threads/Watcher.hs
index 0f76c6a4c..8d06e6659 100644
--- a/Assistant/Threads/Watcher.hs
+++ b/Assistant/Threads/Watcher.hs
@@ -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