aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-02-07 08:28:40 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-02-07 08:28:40 -0400
commitf797939d15a2b414e62b28ccb0bd9e5b77978d76 (patch)
tree4095dd3f6e97bc1d7638cfbecbd1e75ce002af95
parenta7b151f28926f3a6455f4456c496aeaf31df091a (diff)
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.
-rw-r--r--Annex/Content.hs10
-rw-r--r--Annex/Content/Direct.hs7
-rw-r--r--Command/Drop.hs5
-rw-r--r--debian/changelog3
-rw-r--r--doc/bugs/dropunused_doesn__39__t_work_in_my_case__63__.mdwn3
5 files changed, 18 insertions, 10 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index 87ff3f692..8be2cf008 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -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
diff --git a/Annex/Content/Direct.hs b/Annex/Content/Direct.hs
index ec99c1ef4..9e917cf68 100644
--- a/Annex/Content/Direct.hs
+++ b/Annex/Content/Direct.hs
@@ -15,7 +15,6 @@ module Annex.Content.Direct (
recordedCache,
compareCache,
writeCache,
- removeCache,
genCache,
toCache,
Cache(..),
@@ -129,12 +128,6 @@ writeCache key cache = withCacheFile key $ \cachefile -> do
createContentDir cachefile
liftIO $ writeFile cachefile $ showCache cache
-{- Removes a cache. -}
-removeCache :: Key -> Annex ()
-removeCache key = withCacheFile key $ \f -> do
- createContentDir f -- also thaws directory
- liftIO $ nukeFile f
-
{- Cache a file's inode, size, and modification time to determine if it's
- been changed. -}
data Cache = Cache FileID FileOffset EpochTime
diff --git a/Command/Drop.hs b/Command/Drop.hs
index f7491deae..8e5ecc952 100644
--- a/Command/Drop.hs
+++ b/Command/Drop.hs
@@ -60,7 +60,10 @@ performLocal key numcopies knownpresentremote = lockContent key $ do
untrusteduuids <- trustGet UnTrusted
let tocheck = Remote.remotesWithoutUUID remotes (trusteduuids'++untrusteduuids)
stopUnless (canDropKey key numcopies trusteduuids' tocheck []) $ do
- whenM (inAnnex key) $ removeAnnex key
+ whenM (inAnnex key) $
+ removeAnnex key
+ {- Clean up stale direct mode files that may exist. -}
+ cleanObjectLoc key
next $ cleanupLocal key
performRemote :: Key -> Maybe Int -> Remote -> CommandPerform
diff --git a/debian/changelog b/debian/changelog
index f5ae18543..e3faa86b1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -13,6 +13,9 @@ git-annex (3.20130125) UNRELEASED; urgency=low
* pre-commit: Update direct mode mappings.
* uninit, unannex --fast: If hard link creation fails, fall back to slow
mode.
+ * Clean up direct mode cache and mapping info when dropping keys.
+ * dropunused: Clean up stale direct mode cache and mapping info not
+ removed before.
-- Joey Hess <joeyh@debian.org> Sat, 26 Jan 2013 15:48:40 +1100
diff --git a/doc/bugs/dropunused_doesn__39__t_work_in_my_case__63__.mdwn b/doc/bugs/dropunused_doesn__39__t_work_in_my_case__63__.mdwn
index 09bfd0c3b..8f89c0480 100644
--- a/doc/bugs/dropunused_doesn__39__t_work_in_my_case__63__.mdwn
+++ b/doc/bugs/dropunused_doesn__39__t_work_in_my_case__63__.mdwn
@@ -56,3 +56,6 @@ What version of git-annex are you using? On what operating system?
git-annex: 3.20130124
Debian: sid 2013-02-01
+
+> unused being confused by stale data left when switching from direct mode.
+> I've made this be cleaned up. [[done]] --[[Joey]]