summaryrefslogtreecommitdiff
path: root/Command/Reinject.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-09-16 01:17:48 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-09-16 01:17:48 -0400
commit48fd1e629c1192d244fd776c4fc7bd447912df37 (patch)
treeeb3a1cf443d033f5195d8b8d22a79fcbdf35db7d /Command/Reinject.hs
parent719d229d9d0bd87365dd5992d6433da37ae2aca8 (diff)
reinject: When the provided file doesn't match, leave it where it is, rather than moving to .git/annex/bad/
Diffstat (limited to 'Command/Reinject.hs')
-rw-r--r--Command/Reinject.hs22
1 files changed, 12 insertions, 10 deletions
diff --git a/Command/Reinject.hs b/Command/Reinject.hs
index bb277af2c..112b7fadf 100644
--- a/Command/Reinject.hs
+++ b/Command/Reinject.hs
@@ -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