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

@ -209,17 +209,17 @@ checkKeySize :: Key -> Annex Bool
checkKeySize key = do checkKeySize key = do
file <- inRepo $ gitAnnexLocation key file <- inRepo $ gitAnnexLocation key
ifM (liftIO $ doesFileExist file) ifM (liftIO $ doesFileExist file)
( checkKeySize' key file badContent ( checkKeySizeOr badContent key file
, return True , return True
) )
checkKeySizeRemote :: Key -> Remote -> Maybe FilePath -> Annex Bool checkKeySizeRemote :: Key -> Remote -> Maybe FilePath -> Annex Bool
checkKeySizeRemote _ _ Nothing = return True checkKeySizeRemote _ _ Nothing = return True
checkKeySizeRemote key remote (Just file) = checkKeySize' key file checkKeySizeRemote key remote (Just file) =
(badContentRemote remote) checkKeySizeOr (badContentRemote remote) key file
checkKeySize' :: Key -> FilePath -> (Key -> Annex String) -> Annex Bool checkKeySizeOr :: (Key -> Annex String) -> Key -> FilePath -> Annex Bool
checkKeySize' key file bad = case Types.Key.keySize key of checkKeySizeOr bad key file = case Types.Key.keySize key of
Nothing -> return True Nothing -> return True
Just size -> do Just size -> do
size' <- fromIntegral . fileSize size' <- fromIntegral . fileSize
@ -242,15 +242,16 @@ checkKeySize' key file bad = case Types.Key.keySize key of
checkBackend :: Backend -> Key -> Annex Bool checkBackend :: Backend -> Key -> Annex Bool
checkBackend backend key = do checkBackend backend key = do
file <- inRepo (gitAnnexLocation key) file <- inRepo (gitAnnexLocation key)
checkBackend' backend key (Just file) badContent checkBackendOr badContent backend key file
checkBackendRemote :: Backend -> Key -> Remote -> Maybe FilePath -> Annex Bool checkBackendRemote :: Backend -> Key -> Remote -> Maybe FilePath -> Annex Bool
checkBackendRemote backend key remote localcopy = checkBackendRemote backend key remote = maybe (return True) go
checkBackend' backend key localcopy (badContentRemote remote) where
go = checkBackendOr (badContentRemote remote) backend key
checkBackend' :: Backend -> Key -> Maybe FilePath -> (Key -> Annex String) -> Annex Bool checkBackendOr :: (Key -> Annex String) -> Backend -> Key -> FilePath -> Annex Bool
checkBackend' _ _ Nothing _ = return True checkBackendOr bad backend key file =
checkBackend' backend key (Just file) bad = case Types.Backend.fsckKey backend of case Types.Backend.fsckKey backend of
Nothing -> return True Nothing -> return True
Just a -> do Just a -> do
ok <- a key file ok <- a key file

View file

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

2
debian/changelog vendored
View file

@ -18,6 +18,8 @@ git-annex (3.20120826) UNRELEASED; urgency=low
* migrate: Check content before generating the new key, to avoid generating * migrate: Check content before generating the new key, to avoid generating
a key for corrupt data. a key for corrupt data.
* Support repositories created with --separate-git-dir. Closes: #684405 * Support repositories created with --separate-git-dir. Closes: #684405
* reinject: When the provided file doesn't match, leave it where it is,
rather than moving to .git/annex/bad/
-- Joey Hess <joeyh@debian.org> Mon, 27 Aug 2012 13:27:39 -0400 -- Joey Hess <joeyh@debian.org> Mon, 27 Aug 2012 13:27:39 -0400

View file

@ -11,3 +11,5 @@ What version of git-annex are you using? On what operating system?
git-annex version: 3.20120807 git-annex version: 3.20120807
Ubuntu 12.04 updated on Aug 20th Ubuntu 12.04 updated on Aug 20th
annex was installed via cabal on Aug 20th, all other packages are from ubuntu. annex was installed via cabal on Aug 20th, all other packages are from ubuntu.
> [[done]] --[[Joey]]