diff options
author | Joey Hess <joey@kitenet.net> | 2012-09-14 00:18:18 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-09-14 00:18:18 -0400 |
commit | 7f45baee5e7c9e98e6ccf24a6b366dee9d577bc1 (patch) | |
tree | 5fc298b0070364ebedcff59294db8c832670c2ee /Command/Migrate.hs | |
parent | ac67b4ed00928b9399fa4c7147a9c0fcbe0ace5f (diff) |
migrate: Check content before generating the new key, to avoid generating a key for corrupt data.
Diffstat (limited to 'Command/Migrate.hs')
-rw-r--r-- | Command/Migrate.hs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Command/Migrate.hs b/Command/Migrate.hs index c7c0d7af3..d3b29eeca 100644 --- a/Command/Migrate.hs +++ b/Command/Migrate.hs @@ -14,6 +14,7 @@ import qualified Types.Key import Types.KeySource import Annex.Content import qualified Command.ReKey +import qualified Command.Fsck def :: [Command] def = [command "migrate" paramPaths seek "switch data to different backend"] @@ -28,7 +29,7 @@ start file (key, oldbackend) = do if (newbackend /= oldbackend || upgradableKey key) && exists then do showStart "migrate" file - next $ perform file key newbackend + next $ perform file key oldbackend newbackend else stop where choosebackend Nothing = Prelude.head <$> orderedList @@ -42,8 +43,12 @@ upgradableKey key = isNothing $ Types.Key.keySize key {- Store the old backend's key in the new backend - The old backend's key is not dropped from it, because there may - be other files still pointing at that key. -} -perform :: FilePath -> Key -> Backend -> CommandPerform -perform file oldkey newbackend = maybe stop go =<< genkey +perform :: FilePath -> Key -> Backend -> Backend -> CommandPerform +perform file oldkey oldbackend newbackend = do + ifM (Command.Fsck.checkBackend oldbackend oldkey) + ( maybe stop go =<< genkey + , stop + ) where go newkey = stopUnless (Command.ReKey.linkKey oldkey newkey) $ next $ Command.ReKey.cleanup file oldkey newkey |