reinject: When the provided file doesn't match, leave it where it is, rather than moving to .git/annex/bad/

This commit is contained in:
Joey Hess 2012-09-16 01:17:48 -04:00
parent 719d229d9d
commit 48fd1e629c
4 changed files with 35 additions and 28 deletions

View file

@ -35,8 +35,14 @@ start _ = error "specify a src file and a dest file"
perform :: FilePath -> FilePath -> (Key, Backend) -> CommandPerform
perform src _dest (key, backend) = do
unlessM move $ error "mv failed!"
next $ cleanup key backend
{- Check the content before accepting it. -}
ifM (Command.Fsck.checkKeySizeOr reject key src
<&&> Command.Fsck.checkBackendOr reject backend key src)
( do
unlessM move $ error "mv failed!"
next $ cleanup key
, error "not reinjecting"
)
where
-- the file might be on a different filesystem,
-- so mv is used rather than simply calling
@ -44,13 +50,9 @@ perform src _dest (key, backend) = do
-- checked this way.
move = getViaTmp key $ \tmp ->
liftIO $ boolSystem "mv" [File src, File tmp]
reject = const $ return "wrong file?"
cleanup :: Key -> Backend -> CommandCleanup
cleanup key backend = do
cleanup :: Key -> CommandCleanup
cleanup key = do
logStatus key InfoPresent
-- fsck the new content
size_ok <- Command.Fsck.checkKeySize key
backend_ok <- Command.Fsck.checkBackend backend key
return $ size_ok && backend_ok
return True