check Remote.hasKeyCheap again
authorJoey Hess <joeyh@joeyh.name>
Tue, 15 Dec 2020 18:44:00 +0000 (14:44 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 15 Dec 2020 18:44:00 +0000 (14:44 -0400)
In cd1676d604, it stopped using that to avoid surprising behavior
when the location log and remote content were out of sync.
But, it seems that may have changed some behavior users relied on as
well, and also Remote.hasKeyCheap should be faster than checking then
location log.

So, try Remote.hasKeyCheap first, and only if it does not have the key,
fall back to checking the location log. If the location log still thinks
it's present, go ahead and try to get it, so the user will see a failure
rather than silently skipping a file what whereis says is on the remote.

This does make slightly slower the case where the remote does not have
the key, and location log and Remote.hasKeyCheap agree, since it now
checks both. But only 1 stat slower.

Command/Move.hs
doc/forum/What_is_going_on_here__63__/comment_6_536adad665f481a15d4096360d0106c1._comment [new file with mode: 0644]

index 71e29517008476dc9dad764e0bde8a073a60ba1a..584565648a3ee8a051dffb5837063945ec79eca6 100644 (file)
@@ -207,10 +207,22 @@ fromStart removewhen afile key ai si src =
                        fromPerform src removewhen key afile
 
 fromOk :: Remote -> Key -> Annex Bool
-fromOk src key = do
-       u <- getUUID
-       remotes <- Remote.keyPossibilities key
-       return $ u /= Remote.uuid src && elem src remotes
+fromOk src key
+       -- check if the remote contains the key, when it can be done cheaply
+       | Remote.hasKeyCheap src = 
+               Remote.hasKey src key >>= 
+                       Right True -> return True
+                       -- Don't skip getting the key just because the
+                       -- remote no longer contains it if the log
+                       -- says the remote is supposed to contain it;
+                       -- that would be surprising behavior.
+                       _ -> checklog
+       | otherwise = checklog
+  where
+       checklog = do
+               u <- getUUID
+               remotes <- Remote.keyPossibilities key
+               return $ u /= Remote.uuid src && elem src remotes
 
 fromPerform :: Remote -> RemoveWhen -> Key -> AssociatedFile -> CommandPerform
 fromPerform src removewhen key afile = do
diff --git a/doc/forum/What_is_going_on_here__63__/comment_6_536adad665f481a15d4096360d0106c1._comment b/doc/forum/What_is_going_on_here__63__/comment_6_536adad665f481a15d4096360d0106c1._comment
new file mode 100644 (file)
index 0000000..6c209ad
--- /dev/null
@@ -0,0 +1,10 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 6"""
+ date="2020-12-15T18:42:30Z"
+ content="""
+On second thought, it can check as before and only
+if the remote doesn't have the key, fall back to using information from the
+log. That will be faster, and will avoid changing the behavior you were
+relying on. Implemented that.
+"""]]