make Migrate use ReKey rather than the other way around
as ReKey is plumbing, this makes sense
This commit is contained in:
parent
69a0161c3a
commit
156a631f63
3 changed files with 28 additions and 30 deletions
|
@ -12,8 +12,7 @@ import Command
|
||||||
import qualified Backend
|
import qualified Backend
|
||||||
import qualified Types.Key
|
import qualified Types.Key
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
import qualified Command.Add
|
import qualified Command.ReKey
|
||||||
import Logs.Web
|
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [command "migrate" paramPaths seek "switch data to different backend"]
|
def = [command "migrate" paramPaths seek "switch data to different backend"]
|
||||||
|
@ -58,27 +57,8 @@ perform file oldkey newbackend = do
|
||||||
cleantmp tmpfile
|
cleantmp tmpfile
|
||||||
case k of
|
case k of
|
||||||
Nothing -> stop
|
Nothing -> stop
|
||||||
Just (newkey, _) -> stopUnless (linkKey src newkey) $
|
Just (newkey, _) ->
|
||||||
next $ cleanup file oldkey newkey
|
stopUnless (Command.ReKey.linkKey oldkey newkey) $
|
||||||
|
next $ Command.ReKey.cleanup file oldkey newkey
|
||||||
where
|
where
|
||||||
cleantmp t = liftIO $ whenM (doesFileExist t) $ removeFile t
|
cleantmp t = liftIO $ whenM (doesFileExist t) $ removeFile t
|
||||||
|
|
||||||
linkKey :: FilePath -> Key -> Annex Bool
|
|
||||||
linkKey src newkey = getViaTmpUnchecked newkey $ \t -> do
|
|
||||||
-- Make a hard link to the old backend's
|
|
||||||
-- cached key, to avoid wasting disk space.
|
|
||||||
liftIO $ unlessM (doesFileExist t) $ createLink src t
|
|
||||||
return True
|
|
||||||
|
|
||||||
cleanup :: FilePath -> Key -> Key -> CommandCleanup
|
|
||||||
cleanup file oldkey newkey = do
|
|
||||||
-- Update symlink to use the new key.
|
|
||||||
liftIO $ removeFile file
|
|
||||||
|
|
||||||
-- If the old key had some associated urls, record them for
|
|
||||||
-- the new key as well.
|
|
||||||
urls <- getUrls oldkey
|
|
||||||
unless (null urls) $
|
|
||||||
mapM_ (setUrlPresent newkey) urls
|
|
||||||
|
|
||||||
Command.Add.cleanup file newkey True
|
|
||||||
|
|
|
@ -12,7 +12,8 @@ import Command
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import Types.Key
|
import Types.Key
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
import qualified Command.Migrate
|
import qualified Command.Add
|
||||||
|
import Logs.Web
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [command "rekey"
|
def = [command "rekey"
|
||||||
|
@ -36,11 +37,29 @@ perform :: FilePath -> Key -> Key -> CommandPerform
|
||||||
perform file oldkey newkey = do
|
perform file oldkey newkey = do
|
||||||
present <- inAnnex oldkey
|
present <- inAnnex oldkey
|
||||||
_ <- if present
|
_ <- if present
|
||||||
then do
|
then linkKey oldkey newkey
|
||||||
src <- inRepo $ gitAnnexLocation oldkey
|
|
||||||
Command.Migrate.linkKey src newkey
|
|
||||||
else do
|
else do
|
||||||
unlessM (Annex.getState Annex.force) $
|
unlessM (Annex.getState Annex.force) $
|
||||||
error $ file ++ " is not available (use --force to override)"
|
error $ file ++ " is not available (use --force to override)"
|
||||||
return True
|
return True
|
||||||
next $ Command.Migrate.cleanup file oldkey newkey
|
next $ cleanup file oldkey newkey
|
||||||
|
|
||||||
|
{- Make a hard link to the old key content, to avoid wasting disk space. -}
|
||||||
|
linkKey :: Key -> Key -> Annex Bool
|
||||||
|
linkKey oldkey newkey = getViaTmpUnchecked newkey $ \t -> do
|
||||||
|
src <- inRepo $ gitAnnexLocation oldkey
|
||||||
|
liftIO $ unlessM (doesFileExist t) $ createLink src t
|
||||||
|
return True
|
||||||
|
|
||||||
|
cleanup :: FilePath -> Key -> Key -> CommandCleanup
|
||||||
|
cleanup file oldkey newkey = do
|
||||||
|
-- Update symlink to use the new key.
|
||||||
|
liftIO $ removeFile file
|
||||||
|
|
||||||
|
-- If the old key had some associated urls, record them for
|
||||||
|
-- the new key as well.
|
||||||
|
urls <- getUrls oldkey
|
||||||
|
unless (null urls) $
|
||||||
|
mapM_ (setUrlPresent newkey) urls
|
||||||
|
|
||||||
|
Command.Add.cleanup file newkey True
|
||||||
|
|
1
Usage.hs
1
Usage.hs
|
@ -11,7 +11,6 @@ import Common.Annex
|
||||||
import System.Console.GetOpt
|
import System.Console.GetOpt
|
||||||
|
|
||||||
import Types.Command
|
import Types.Command
|
||||||
import Types.Option
|
|
||||||
|
|
||||||
{- Usage message with lists of commands and options. -}
|
{- Usage message with lists of commands and options. -}
|
||||||
usage :: String -> [Command] -> [Option] -> String
|
usage :: String -> [Command] -> [Option] -> String
|
||||||
|
|
Loading…
Reference in a new issue