2011-10-31 16:33:41 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2016-04-22 17:49:32 +00:00
|
|
|
- Copyright 2011-2016 Joey Hess <id@joeyh.name>
|
2011-10-31 16:33:41 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2011-10-31 19:18:41 +00:00
|
|
|
module Command.Reinject where
|
2011-10-31 16:33:41 +00:00
|
|
|
|
|
|
|
import Command
|
|
|
|
import Logs.Location
|
|
|
|
import Annex.Content
|
2016-04-22 17:49:32 +00:00
|
|
|
import Backend
|
|
|
|
import Types.KeySource
|
2011-10-31 16:33:41 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
cmd :: Command
|
|
|
|
cmd = command "reinject" SectionUtility
|
2016-04-22 17:49:32 +00:00
|
|
|
"inject content of file back into annex"
|
|
|
|
(paramRepeating (paramPair "SRC" "DEST")
|
|
|
|
`paramOr` "--known " ++ paramRepeating "SRC")
|
|
|
|
(seek <$$> optParser)
|
2011-10-31 16:33:41 +00:00
|
|
|
|
2016-04-22 17:49:32 +00:00
|
|
|
data ReinjectOptions = ReinjectOptions
|
|
|
|
{ params :: CmdParams
|
|
|
|
, knownOpt :: Bool
|
|
|
|
}
|
2011-10-31 16:33:41 +00:00
|
|
|
|
2016-04-22 17:49:32 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser ReinjectOptions
|
|
|
|
optParser desc = ReinjectOptions
|
|
|
|
<$> cmdParams desc
|
|
|
|
<*> switch
|
|
|
|
( long "known"
|
|
|
|
<> help "inject all known files"
|
|
|
|
<> hidden
|
|
|
|
)
|
|
|
|
|
|
|
|
seek :: ReinjectOptions -> CommandSeek
|
|
|
|
seek os
|
|
|
|
| knownOpt os = withStrings startKnown (params os)
|
|
|
|
| otherwise = withWords startSrcDest (params os)
|
|
|
|
|
|
|
|
startSrcDest :: [FilePath] -> CommandStart
|
|
|
|
startSrcDest (src:dest:[])
|
2011-10-31 20:46:51 +00:00
|
|
|
| src == dest = stop
|
2016-04-22 17:49:32 +00:00
|
|
|
| otherwise = notAnnexed src $ do
|
2012-11-12 05:05:04 +00:00
|
|
|
showStart "reinject" dest
|
2016-04-22 17:49:32 +00:00
|
|
|
next $ ifAnnexed dest
|
|
|
|
(perform src)
|
|
|
|
stop
|
|
|
|
startSrcDest _ = error "specify a src file and a dest file"
|
|
|
|
|
|
|
|
startKnown :: FilePath -> CommandStart
|
|
|
|
startKnown src = notAnnexed src $ do
|
|
|
|
showStart "reinject" src
|
|
|
|
mkb <- genKey (KeySource src src Nothing) Nothing
|
|
|
|
case mkb of
|
|
|
|
Nothing -> error "Failed to generate key"
|
|
|
|
Just (key, _) -> ifM (isKnownKey key)
|
|
|
|
( next $ perform src key
|
|
|
|
, do
|
|
|
|
warning "Not known content; skipping"
|
|
|
|
next $ next $ return True
|
|
|
|
)
|
|
|
|
|
|
|
|
notAnnexed :: FilePath -> CommandStart -> CommandStart
|
|
|
|
notAnnexed src = ifAnnexed src (error $ "cannot used annexed file as src: " ++ src)
|
2011-10-31 16:33:41 +00:00
|
|
|
|
2016-04-22 17:49:32 +00:00
|
|
|
perform :: FilePath -> Key -> CommandPerform
|
|
|
|
perform src key = ifM move
|
Do verification of checksums of annex objects downloaded from remotes.
* When annex objects are received into git repositories, their checksums are
verified then too.
* To get the old, faster, behavior of not verifying checksums, set
annex.verify=false, or remote.<name>.annex-verify=false.
* setkey, rekey: These commands also now verify that the provided file
matches the key, unless annex.verify=false.
* reinject: Already verified content; this can now be disabled by
setting annex.verify=false.
recvkey and reinject already did verification, so removed now duplicate
code from them. fsck still does its own verification, which is ok since it
does not use getViaTmp, so verification doesn't happen twice when using fsck
--from.
2015-10-01 19:54:37 +00:00
|
|
|
( next $ cleanup key
|
|
|
|
, error "failed"
|
|
|
|
)
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2016-04-20 17:21:56 +00:00
|
|
|
move = checkDiskSpaceToGet key False $
|
|
|
|
ifM (verifyKeyContent DefaultVerify UnVerified key src)
|
|
|
|
( do
|
|
|
|
moveAnnex key src
|
|
|
|
return True
|
|
|
|
, return False
|
|
|
|
)
|
2011-10-31 16:33:41 +00:00
|
|
|
|
2012-09-16 05:17:48 +00:00
|
|
|
cleanup :: Key -> CommandCleanup
|
|
|
|
cleanup key = do
|
2011-10-31 16:33:41 +00:00
|
|
|
logStatus key InfoPresent
|
2012-09-16 05:17:48 +00:00
|
|
|
return True
|