deal with unlocked files

P2P protocol version 1 adds VALID|INVALID after DATA; INVALID means the
file was detected to change content while it was being sent and so we
may not have received the valid content of the file.

Added new MustVerify constructor for Verification, which forces
verification even when annex.verify=false etc. This is used when INVALID
and in protocol version 0.

As well as changing git-annex-shell p2psdio, this makes git-annex tor
remotes always force verification, since they don't yet use protocol
version 1. Previously, annex.verify=false could skip verification when
using tor remotes, and let bad data into the repository.

This commit was sponsored by Jack Hill on Patreon.
This commit is contained in:
Joey Hess 2018-03-13 14:18:30 -04:00
parent 9930b1f140
commit 31e1adc005
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
10 changed files with 141 additions and 78 deletions

View file

@ -16,7 +16,7 @@ module Annex.Content (
lockContentForRemoval,
ContentRemovalLock,
getViaTmp,
getViaTmp',
getViaTmpFromDisk,
checkDiskSpaceToGet,
prepTmp,
withTmp,
@ -295,13 +295,13 @@ lockContentUsing locker key a = do
- the key and moves the file into the annex as a key's content. -}
getViaTmp :: VerifyConfig -> Key -> (FilePath -> Annex (Bool, Verification)) -> Annex Bool
getViaTmp v key action = checkDiskSpaceToGet key False $
getViaTmp' v key action
getViaTmpFromDisk v key action
{- Like getViaTmp, but does not check that there is enough disk space
- for the incoming key. For use when the key content is already on disk
- and not being copied into place. -}
getViaTmp' :: VerifyConfig -> Key -> (FilePath -> Annex (Bool, Verification)) -> Annex Bool
getViaTmp' v key action = do
getViaTmpFromDisk :: VerifyConfig -> Key -> (FilePath -> Annex (Bool, Verification)) -> Annex Bool
getViaTmpFromDisk v key action = do
tmpfile <- prepTmp key
(ok, verification) <- action tmpfile
if ok
@ -331,12 +331,15 @@ getViaTmp' v key action = do
- it is checked.
-}
verifyKeyContent :: VerifyConfig -> Verification -> Key -> FilePath -> Annex Bool
verifyKeyContent _ Verified _ _ = return True
verifyKeyContent v UnVerified k f = ifM (shouldVerify v)
( verifysize <&&> verifycontent
, return True
)
verifyKeyContent v verification k f = case verification of
Verified -> return True
UnVerified -> ifM (shouldVerify v)
( verify
, return True
)
MustVerify -> verify
where
verify = verifysize <&&> verifycontent
verifysize = case keySize k of
Nothing -> return True
Just size -> do