From 06046a0d2b3479147db3133de1227f86d43d4e6a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 11 Mar 2013 14:14:45 -0400 Subject: [PATCH] finish fast direct mode rename handling. wow, it's fast --- Assistant/Threads/Committer.hs | 32 +++++++++++++++----------------- Command/Add.hs | 14 +++++++++----- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Assistant/Threads/Committer.hs b/Assistant/Threads/Committer.hs index e77c55dfd9..f1e26f9aa7 100644 --- a/Assistant/Threads/Committer.hs +++ b/Assistant/Threads/Committer.hs @@ -266,14 +266,13 @@ handleAdds delayadd cs = returnWhen (null incomplete) $ do Just cache -> case M.lookup (inodeCacheToKey ct cache) m of Nothing -> add c - Just k -> fastadd c k cache + Just k -> fastadd c k - fastadd :: Change -> Key -> InodeCache -> Assistant (Maybe Change) - fastadd change key cache = do - -- TODO do fast method - debug ["rename detected", show change, show key, show cache] - add change - --return $ Just $ finishedChange change key + fastadd :: Change -> Key -> Assistant (Maybe Change) + fastadd change key = do + let source = keySource change + liftAnnex $ Command.Add.finishIngestDirect key source + done change (keyFilename source) key removedKeysMap :: InodeComparisonType -> [Change] -> Annex (M.Map InodeCacheKey Key) removedKeysMap ct l = do @@ -291,16 +290,15 @@ handleAdds delayadd cs = returnWhen (null incomplete) $ do liftAnnex showEndFail return Nothing - done change file key = do - liftAnnex $ do - logStatus key InfoPresent - link <- ifM isDirect - ( calcGitLink file key - , Command.Add.link file key True - ) - whenM (pure DirWatcher.eventsCoalesce <||> isDirect) $ do - stageSymlink file =<< hashSymlink link - showEndOk + done change file key = liftAnnex $ do + logStatus key InfoPresent + link <- ifM isDirect + ( calcGitLink file key + , Command.Add.link file key True + ) + whenM (pure DirWatcher.eventsCoalesce <||> isDirect) $ do + stageSymlink file =<< hashSymlink link + showEndOk return $ Just $ finishedChange change key {- Check that the keysource's keyFilename still exists, diff --git a/Command/Add.hs b/Command/Add.hs index 7100006c64..343ffbe95f 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -125,11 +125,7 @@ ingest (Just source) = do godirect (Just (key, _)) (Just cache) = do writeInodeCache key cache - void $ addAssociatedFile key $ keyFilename source - unlessM crippledFileSystem $ - liftIO $ allowWrite $ keyFilename source - when (contentLocation source /= keyFilename source) $ - liftIO $ nukeFile $ contentLocation source + finishIngestDirect key source return $ Just key godirect _ _ = failure @@ -138,6 +134,14 @@ ingest (Just source) = do liftIO $ nukeFile $ contentLocation source return Nothing +finishIngestDirect :: Key -> KeySource -> Annex () +finishIngestDirect key source = do + void $ addAssociatedFile key $ keyFilename source + unlessM crippledFileSystem $ + liftIO $ allowWrite $ keyFilename source + when (contentLocation source /= keyFilename source) $ + liftIO $ nukeFile $ contentLocation source + perform :: FilePath -> CommandPerform perform file = maybe stop (\key -> next $ cleanup file key True)