fix handling of corrupted data received from git remote

Recover from corrupted content being received from a git remote due eg to a
wire error, by deleting the temporary file when it fails to verify. This
prevents a retry from failing again.

Reversion introduced in version 8.20210903, when incremental verification
was added.

Only the git remote seems to be affected, although it is certianly
possible that other remotes could later have the same issue. This only
affects things passed to getViaTmp that return (False, UnVerified) due to
verification failing. As far as getViaTmp can tell, that could just as well
mean that the transfer failed in a way that would resume, so it cannot
delete the temp file itself. Remote.Git and P2P.Annex use getViaTmp internally,
while other remotes do not, which is why only it seems affected.

A better fix perhaps would be to improve the types of the callback
passed to getViaTmp, so that some other value could be used to indicate
the state where the transfer succeeded but verification failed.

Sponsored-by: Boyd Stephen Smith Jr.
This commit is contained in:
Joey Hess 2022-01-07 13:17:43 -04:00
parent 21c0d5be6e
commit e95747a149
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 39 additions and 20 deletions

View file

@ -30,6 +30,7 @@ import Logs.Presence
import Annex.Transfer
import Annex.CopyFile
import Annex.Verify
import Annex.Content (verificationOfContentFailed)
import Annex.UUID
import qualified Annex.Content
import qualified Annex.BranchState
@ -706,7 +707,9 @@ mkFileCopier remotewanthardlink (State _ _ copycowtried _ _) = do
ifM (liftIO (catchBoolIO (linker src dest)))
( ifM check
( return (True, Verified)
, return (False, UnVerified)
, do
verificationOfContentFailed (toRawFilePath dest)
return (False, UnVerified)
)
, copier src dest k p check verifyconfig
)
@ -717,7 +720,9 @@ mkFileCopier remotewanthardlink (State _ _ copycowtried _ _) = do
fileCopier copycowtried src dest p iv >>= \case
Copied -> ifM check
( finishVerifyKeyContentIncrementally iv
, return (False, UnVerified)
, do
verificationOfContentFailed (toRawFilePath dest)
return (False, UnVerified)
)
CopiedCoW -> unVerified check