From 829ae9100968e8b18f74d78df869bd3a508599a9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 30 Dec 2015 14:23:31 -0400 Subject: [PATCH] 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. --- Annex/WorkTree.hs | 7 +++++-- Test.hs | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Annex/WorkTree.hs b/Annex/WorkTree.hs index c824e7fc59..85ea9a62e7 100644 --- a/Annex/WorkTree.hs +++ b/Annex/WorkTree.hs @@ -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 diff --git a/Test.hs b/Test.hs index 2d22735f76..6439694402 100644 --- a/Test.hs +++ b/Test.hs @@ -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.