check Remote.hasKeyCheap again

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.
This commit is contained in:
Joey Hess 2020-12-15 14:44:00 -04:00
parent c2a5f3c44f
commit f29d49d478
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 26 additions and 4 deletions

View 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

View file

@ -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.
"""]]