diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-11-06 15:28:20 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-11-06 15:28:20 -0400 |
commit | 90d833e44240dd0a83fd2439fa1a23e490959235 (patch) | |
tree | 9a0f4bed733aa274422d932c761b972a754cdd34 /Command/Add.hs | |
parent | d2ab9f9c90e8a73f99bfad452fd17cc2f77ad230 (diff) |
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!
Diffstat (limited to 'Command/Add.hs')
-rw-r--r-- | Command/Add.hs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Command/Add.hs b/Command/Add.hs index 94a19fba5..fd92f04ef 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -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 |