reinject: When src file's content cannot be verified, leave it alone, instead of deleting it.
This commit is contained in:
parent
bb92b45fb7
commit
9d952fe9d1
5 changed files with 31 additions and 19 deletions
|
@ -18,8 +18,6 @@ module Annex.Content (
|
||||||
getViaTmp,
|
getViaTmp,
|
||||||
getViaTmp',
|
getViaTmp',
|
||||||
checkDiskSpaceToGet,
|
checkDiskSpaceToGet,
|
||||||
VerifyConfig(..),
|
|
||||||
Types.Remote.unVerified,
|
|
||||||
prepTmp,
|
prepTmp,
|
||||||
withTmp,
|
withTmp,
|
||||||
checkDiskSpace,
|
checkDiskSpace,
|
||||||
|
@ -45,6 +43,10 @@ module Annex.Content (
|
||||||
withObjectLoc,
|
withObjectLoc,
|
||||||
staleKeysPrune,
|
staleKeysPrune,
|
||||||
isUnmodified,
|
isUnmodified,
|
||||||
|
verifyKeyContent,
|
||||||
|
VerifyConfig(..),
|
||||||
|
Verification(..),
|
||||||
|
unVerified,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import System.IO.Unsafe (unsafeInterleaveIO)
|
import System.IO.Unsafe (unsafeInterleaveIO)
|
||||||
|
@ -71,6 +73,7 @@ import qualified Annex.Content.Direct as Direct
|
||||||
import Annex.ReplaceFile
|
import Annex.ReplaceFile
|
||||||
import Annex.LockPool
|
import Annex.LockPool
|
||||||
import Messages.Progress
|
import Messages.Progress
|
||||||
|
import Types.Remote (unVerified, Verification(..))
|
||||||
import qualified Types.Remote
|
import qualified Types.Remote
|
||||||
import qualified Types.Backend
|
import qualified Types.Backend
|
||||||
import qualified Backend
|
import qualified Backend
|
||||||
|
@ -290,14 +293,14 @@ lockContentUsing locker key a = do
|
||||||
{- Runs an action, passing it the temp file to get,
|
{- Runs an action, passing it the temp file to get,
|
||||||
- and if the action succeeds, verifies the file matches
|
- and if the action succeeds, verifies the file matches
|
||||||
- the key and moves the file into the annex as a key's content. -}
|
- the key and moves the file into the annex as a key's content. -}
|
||||||
getViaTmp :: VerifyConfig -> Key -> (FilePath -> Annex (Bool, Types.Remote.Verification)) -> Annex Bool
|
getViaTmp :: VerifyConfig -> Key -> (FilePath -> Annex (Bool, Verification)) -> Annex Bool
|
||||||
getViaTmp v key action = checkDiskSpaceToGet key False $
|
getViaTmp v key action = checkDiskSpaceToGet key False $
|
||||||
getViaTmp' v key action
|
getViaTmp' v key action
|
||||||
|
|
||||||
{- Like getViaTmp, but does not check that there is enough disk space
|
{- 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
|
- for the incoming key. For use when the key content is already on disk
|
||||||
- and not being copied into place. -}
|
- and not being copied into place. -}
|
||||||
getViaTmp' :: VerifyConfig -> Key -> (FilePath -> Annex (Bool, Types.Remote.Verification)) -> Annex Bool
|
getViaTmp' :: VerifyConfig -> Key -> (FilePath -> Annex (Bool, Verification)) -> Annex Bool
|
||||||
getViaTmp' v key action = do
|
getViaTmp' v key action = do
|
||||||
tmpfile <- prepTmp key
|
tmpfile <- prepTmp key
|
||||||
(ok, verification) <- action tmpfile
|
(ok, verification) <- action tmpfile
|
||||||
|
@ -325,9 +328,9 @@ getViaTmp' v key action = do
|
||||||
- When the key's backend allows verifying the content (eg via checksum),
|
- When the key's backend allows verifying the content (eg via checksum),
|
||||||
- it is checked.
|
- it is checked.
|
||||||
-}
|
-}
|
||||||
verifyKeyContent :: VerifyConfig -> Types.Remote.Verification -> Key -> FilePath -> Annex Bool
|
verifyKeyContent :: VerifyConfig -> Verification -> Key -> FilePath -> Annex Bool
|
||||||
verifyKeyContent _ Types.Remote.Verified _ _ = return True
|
verifyKeyContent _ Verified _ _ = return True
|
||||||
verifyKeyContent v Types.Remote.UnVerified k f = ifM (shouldVerify v)
|
verifyKeyContent v UnVerified k f = ifM (shouldVerify v)
|
||||||
( verifysize <&&> verifycontent
|
( verifysize <&&> verifycontent
|
||||||
, return True
|
, return True
|
||||||
)
|
)
|
||||||
|
@ -786,7 +789,7 @@ isUnmodified key f = go =<< geti
|
||||||
go (Just fc) = cheapcheck fc <||> expensivecheck fc
|
go (Just fc) = cheapcheck fc <||> expensivecheck fc
|
||||||
cheapcheck fc = anyM (compareInodeCaches fc)
|
cheapcheck fc = anyM (compareInodeCaches fc)
|
||||||
=<< Database.Keys.getInodeCaches key
|
=<< Database.Keys.getInodeCaches key
|
||||||
expensivecheck fc = ifM (verifyKeyContent AlwaysVerify Types.Remote.UnVerified key f)
|
expensivecheck fc = ifM (verifyKeyContent AlwaysVerify UnVerified key f)
|
||||||
-- The file could have been modified while it was
|
-- The file could have been modified while it was
|
||||||
-- being verified. Detect that.
|
-- being verified. Detect that.
|
||||||
( geti >>= maybe (return False) (compareInodeCaches fc)
|
( geti >>= maybe (return False) (compareInodeCaches fc)
|
||||||
|
|
|
@ -38,14 +38,13 @@ perform src _dest key = ifM move
|
||||||
, error "failed"
|
, error "failed"
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
-- The file might be on a different filesystem,
|
move = checkDiskSpaceToGet key False $
|
||||||
-- so moveFile is used rather than simply calling
|
ifM (verifyKeyContent DefaultVerify UnVerified key src)
|
||||||
-- moveToObjectDir; disk space is also checked this way,
|
( do
|
||||||
-- and the file's content is verified to match the key.
|
moveAnnex key src
|
||||||
move = getViaTmp DefaultVerify key $ \tmp -> unVerified $
|
return True
|
||||||
liftIO $ catchBoolIO $ do
|
, return False
|
||||||
moveFile src tmp
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
cleanup :: Key -> CommandCleanup
|
cleanup :: Key -> CommandCleanup
|
||||||
cleanup key = do
|
cleanup key = do
|
||||||
|
|
|
@ -11,7 +11,7 @@ import Command
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
import qualified Types.Remote as Remote
|
import qualified Types.Remote as Remote
|
||||||
import Types.Backend (getKey, verifyKeyContent)
|
import qualified Types.Backend as Backend
|
||||||
import Types.KeySource
|
import Types.KeySource
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
import Backend
|
import Backend
|
||||||
|
@ -151,7 +151,7 @@ test st r k =
|
||||||
(== Right b) <$> Remote.hasKey r k
|
(== Right b) <$> Remote.hasKey r k
|
||||||
fsck = case maybeLookupBackendName (keyBackendName k) of
|
fsck = case maybeLookupBackendName (keyBackendName k) of
|
||||||
Nothing -> return True
|
Nothing -> return True
|
||||||
Just b -> case verifyKeyContent b of
|
Just b -> case Backend.verifyKeyContent b of
|
||||||
Nothing -> return True
|
Nothing -> return True
|
||||||
Just verifier -> verifier k (key2file k)
|
Just verifier -> verifier k (key2file k)
|
||||||
get = getViaTmp (RemoteVerify r) k $ \dest ->
|
get = getViaTmp (RemoteVerify r) k $ \dest ->
|
||||||
|
@ -224,6 +224,6 @@ randKey sz = withTmpFile "randkey" $ \f h -> do
|
||||||
, inodeCache = Nothing
|
, inodeCache = Nothing
|
||||||
}
|
}
|
||||||
k <- fromMaybe (error "failed to generate random key")
|
k <- fromMaybe (error "failed to generate random key")
|
||||||
<$> getKey Backend.Hash.testKeyBackend ks
|
<$> Backend.getKey Backend.Hash.testKeyBackend ks
|
||||||
moveAnnex k f
|
moveAnnex k f
|
||||||
return k
|
return k
|
||||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -4,6 +4,8 @@ git-annex (6.20160419) UNRELEASED; urgency=medium
|
||||||
over http with -J.
|
over http with -J.
|
||||||
* Avoid setting LOCPATH in linux standalone builds now that ghc has been
|
* Avoid setting LOCPATH in linux standalone builds now that ghc has been
|
||||||
fixed to not hang when it cannot find locale files.
|
fixed to not hang when it cannot find locale files.
|
||||||
|
* reinject: When src file's content cannot be verified, leave it alone,
|
||||||
|
instead of deleting it.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Tue, 19 Apr 2016 12:57:15 -0400
|
-- Joey Hess <id@joeyh.name> Tue, 19 Apr 2016 12:57:15 -0400
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
[[!comment format=mdwn
|
||||||
|
username="joey"
|
||||||
|
subject="""comment 3"""
|
||||||
|
date="2016-04-20T17:20:10Z"
|
||||||
|
content="""
|
||||||
|
Good point about reinject deleting files that don't verify. I've fixed that
|
||||||
|
so it leaves them alone.
|
||||||
|
"""]]
|
Loading…
Add table
Add a link
Reference in a new issue