Clean up direct mode cache and mapping info when dropping keys.

These files were left behind, and made getKeysPresent find keys that were
not present. It would be expensive to make getKeysPresent check that the
actual key files are present (it just lists the directories). But that's not
needed if we just clean up the stale cache and mapping files.

To handle systems that were in direct mode and got switched back with stale
direct mode files, made cleanObjectLoc remove all files in the key's directory.

git annex unused will still list keys that are gone but for which the stale
direct mode files exists. To deal with that, made dropunused remove the key's
directory even if the key does not seem to be present.
This commit is contained in:
Joey Hess 2013-02-07 08:28:40 -04:00
parent 21cfce02ee
commit 57780cb3a4
5 changed files with 18 additions and 10 deletions

View file

@ -28,6 +28,7 @@ module Annex.Content (
freezeContent,
thawContent,
replaceFile,
cleanObjectLoc,
) where
import System.IO.Unsafe (unsafeInterleaveIO)
@ -334,7 +335,12 @@ withObjectLoc key indirect direct = ifM isDirect
cleanObjectLoc :: Key -> Annex ()
cleanObjectLoc key = do
file <- inRepo $ gitAnnexLocation key
liftIO $ removeparents file (3 :: Int)
liftIO $ do
let dir = parentDir file
void $ catchMaybeIO $ do
allowWrite dir
removeDirectoryRecursive dir
removeparents dir (2 :: Int)
where
removeparents _ 0 = noop
removeparents file n = do
@ -356,8 +362,8 @@ removeAnnex key = withObjectLoc key remove removedirect
cleanObjectLoc key
removedirect fs = do
cache <- recordedCache key
removeCache key
mapM_ (resetfile cache) fs
cleanObjectLoc key
resetfile cache f = whenM (compareCache f cache) $ do
l <- calcGitLink f key
top <- fromRepo Git.repoPath