summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-23 14:58:14 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-23 14:58:14 -0400
commit3cf16c9883d63247cceb1f8cf2ce41d43b7a214e (patch)
tree8724d11cb5967a4f8616ceec0ad04beb37f26dad
parentf05ed818f9e8e49b646805402be928f9c89c9a7f (diff)
incomplete
-rw-r--r--Commands.hs11
-rw-r--r--Remotes.hs42
2 files changed, 36 insertions, 17 deletions
diff --git a/Commands.hs b/Commands.hs
index 011481bd8..ffa3576cf 100644
--- a/Commands.hs
+++ b/Commands.hs
@@ -308,12 +308,13 @@ moveTo file = isAnnexed file $ \(key, backend) -> do
isthere <- Remotes.inAnnex remote key
case isthere of
Left err -> error (show err)
- Right True -> removeit
- Right False -> moveit
+ Right False -> moveit remote key
+ Right True -> removeit remote key
where
- moveit = do
- error $ "TODO move" ++ file
- removeit = do
+ moveit remote key = do
+ Remotes.copyToRemote remote key
+ removeit remote key
+ removeit remote key = do
error $ "TODO remove" ++ file
{- Moves the content of an annexed file from another repository to the current
diff --git a/Remotes.hs b/Remotes.hs
index c1cab73c6..4cfcfdffd 100644
--- a/Remotes.hs
+++ b/Remotes.hs
@@ -6,7 +6,8 @@ module Remotes (
tryGitConfigRead,
inAnnex,
commandLineRemote,
- copyFromRemote
+ copyFromRemote,
+ copyToRemote
) where
import Control.Exception
@@ -70,13 +71,11 @@ keyPossibilities key = do
return $ null u
{- Checks if a given remote has the content for a key inAnnex.
- -
- - This is done by constructing a new Annex monad using the remote.
- -
- If the remote cannot be accessed, returns a Left error.
-}
inAnnex :: Git.Repo -> Key -> Annex (Either IOException Bool)
inAnnex remote key = do
+ -- the check needs to run in an Annex monad using the remote
a <- liftIO $ Annex.new remote []
liftIO $ ((try $ check a)::IO (Either IOException Bool))
where
@@ -181,7 +180,7 @@ tryGitConfigRead r = do
then new:(exchange ls new)
else old:(exchange ls new)
-{- Tries to copy a file from a remote. -}
+{- Tries to copy a key's content from a remote to a file. -}
copyFromRemote :: Git.Repo -> Key -> FilePath -> Annex Bool
copyFromRemote r key file = do
-- annexLocation needs the git config to have been read for a remote,
@@ -189,13 +188,13 @@ copyFromRemote r key file = do
result <- tryGitConfigRead r
case (result) of
Left err -> return False
- Right r' -> copy r'
+ Right from -> copy from
where
- copy r = do
- Core.showNote $ "copying from " ++ (Git.repoDescribe r) ++ "..."
- if (not $ Git.repoIsUrl r)
+ copy from = do
+ Core.showNote $ "copying from " ++ (Git.repoDescribe from) ++ "..."
+ if (not $ Git.repoIsUrl from)
then getlocal
- else if (Git.repoIsSsh r)
+ else if (Git.repoIsSsh from)
then getssh
else error "copying from non-ssh repo not supported"
where
@@ -203,5 +202,24 @@ copyFromRemote r key file = do
getssh = do
liftIO $ putStrLn "" -- make way for scp progress bar
liftIO $ boolSystem "scp" [sshlocation, file]
- location = annexLocation r key
- sshlocation = (Git.urlHost r) ++ ":" ++ location
+ location = annexLocation from key
+ sshlocation = (Git.urlHost from) ++ ":" ++ location
+
+{- Tries to copy a key's content to a remote. -}
+copyToRemote :: Git.Repo -> Key -> Annex Bool
+copyToRemote r key = do
+ g <- Annex.gitRepo
+ Core.showNote $ "copying to " ++ (Git.repoDescribe r) ++ "..."
+ if (not $ Git.repoIsUrl r)
+ then sendlocal g
+ else if (Git.repoIsSsh r)
+ then sendssh g
+ else error "copying to non-ssh repo not supported"
+ where
+ sendlocal g = liftIO $ boolSystem "cp" ["-a", location g, file]
+ sendssh g = do
+ liftIO $ putStrLn "" -- make way for scp progress bar
+ liftIO $ boolSystem "scp" [location g, sshlocation]
+ location g = annexLocation g key
+ sshlocation = (Git.urlHost r) ++ ":" ++ file
+ file = error "TODO"