fix failing git-annex unused test case in v6

WorkTree.lookupFile was finding a key for a file that's deleted from the
work tree, which is different than the v5 behavior (though perhaps the same
as the direct mode behavior). Fix by checking that the work tree file exists
before catting its key.

Hopefully this won't slow down much, probably the catKey is much more expensive.
I can't see any way to optimise this, except perhaps to make Command.Unused
check if work tree files exist before/after calling lookupFile. But,
it seems better to make lookupFile really only find keys for worktree files;
that's what it's intended to do.
This commit is contained in:
Joey Hess 2015-12-30 14:23:31 -04:00
parent 6c1cf8267d
commit 829ae91009
Failed to extract signature
2 changed files with 9 additions and 6 deletions

View file

@ -13,7 +13,7 @@ import Annex.CatFile
import Annex.Version
import Config
{- Looks up the key corresponding to an annexed file,
{- Looks up the key corresponding to an annexed file in the work tree,
- by examining what the file links to.
-
- An unlocked file will not have a link on disk, so fall back to
@ -25,7 +25,10 @@ lookupFile file = do
case mkey of
Just key -> makeret key
Nothing -> ifM (versionSupportsUnlockedPointers <||> isDirect)
( maybe (return Nothing) makeret =<< catKeyFile file
( ifM (liftIO $ doesFileExist file)
( maybe (return Nothing) makeret =<< catKeyFile file
, return Nothing
)
, return Nothing
)
where

View file

@ -123,7 +123,7 @@ tests = testGroup "Tests" $ properties :
map (\(d, te) -> withTestMode te (unitTests d)) testmodes
where
testmodes =
--[ ("v6", TestMode { forceDirect = False, annexVersion = "6" })
-- [ ("v6", TestMode { forceDirect = False, annexVersion = "6" })
[ ("v5", TestMode { forceDirect = False, annexVersion = "5" })
-- Windows will only use direct mode, so don't test twice.
#ifndef mingw32_HOST_OS
@ -798,8 +798,8 @@ test_unused = intmpclonerepoInDirect $ do
checkunused [] "after dropunused"
not <$> git_annex "dropunused" ["--force", "10", "501"] @? "dropunused failed to fail on bogus numbers"
-- unused used to miss symlinks that were not staged and pointed
-- at annexed content, and think that content was unused
-- unused used to miss renamed symlinks that were not staged
-- and pointed at annexed content, and think that content was unused
writeFile "unusedfile" "unusedcontent"
git_annex "add" ["unusedfile"] @? "add of unusedfile failed"
unusedfilekey <- annexeval $ findkey "unusedfile"
@ -807,7 +807,7 @@ test_unused = intmpclonerepoInDirect $ do
boolSystem "git" [Param "rm", Param "-qf", File "unusedfile"] @? "git rm failed"
checkunused [] "with unstaged link"
removeFile "unusedunstagedfile"
checkunused [unusedfilekey] "with unstaged link deleted"
checkunused [unusedfilekey] "with renamed link deleted"
-- unused used to miss symlinks that were deleted or modified
-- manually, but commited as such.