add: Fix error recovery rollback to not move the injested file content out of the annex back to the file, because other files may point to that same content. Instead, copy the injected file content out to recover.

That was not a data loss, but it came close!
This commit is contained in:
Joey Hess 2015-11-06 15:28:20 -04:00
parent d435a717e6
commit 7938b87864
Failed to extract signature
3 changed files with 11 additions and 16 deletions

View file

@ -31,6 +31,7 @@ import Utility.InodeCache
import Annex.FileMatcher
import Annex.ReplaceFile
import Utility.Tmp
import Utility.CopyFile
import Control.Exception (IOException)
@ -244,15 +245,13 @@ undo :: FilePath -> Key -> SomeException -> Annex a
undo file key e = do
whenM (inAnnex key) $ do
liftIO $ nukeFile file
catchNonAsync (fromAnnex key file) tryharder
logStatus key InfoMissing
-- The key could be used by other files too, so leave the
-- content in the annex, and make a copy back to the file.
obj <- calcRepo $ gitAnnexLocation key
unlessM (liftIO $ copyFileExternal CopyTimeStamps obj file) $
warning $ "Unable to restore content of " ++ file ++ "; it should be located in " ++ obj
thawContent file
throwM e
where
-- fromAnnex could fail if the file ownership is weird
tryharder :: SomeException -> Annex ()
tryharder _ = do
src <- calcRepo $ gitAnnexLocation key
liftIO $ moveFile src file
{- Creates the symlink to the annexed content, returns the link target. -}
link :: FilePath -> Key -> Maybe InodeCache -> Annex String