git annex move --from remote almost working
This commit is contained in:
parent
3f0de706dd
commit
1aa19422ac
4 changed files with 88 additions and 32 deletions
69
Commands.hs
69
Commands.hs
|
@ -367,25 +367,28 @@ moveToPerform file key = do
|
||||||
remote <- Remotes.commandLineRemote
|
remote <- Remotes.commandLineRemote
|
||||||
isthere <- Remotes.inAnnex remote key
|
isthere <- Remotes.inAnnex remote key
|
||||||
case isthere of
|
case isthere of
|
||||||
Left err -> error (show err)
|
Left err -> do
|
||||||
Right False -> moveit remote key
|
showNote $ show err
|
||||||
Right True -> removeit remote key
|
return Nothing
|
||||||
where
|
Right False -> do
|
||||||
moveit remote key = do
|
ok <- Remotes.copyToRemote remote key
|
||||||
Remotes.copyToRemote remote key
|
if (ok)
|
||||||
removeit remote key
|
then return $ Just $ moveToCleanup remote key
|
||||||
removeit remote key = do
|
else return Nothing -- failed
|
||||||
error "TODO: drop key from local"
|
Right True -> return $ Just $ moveToCleanup remote key
|
||||||
return $ Just $ moveToCleanup remote key
|
|
||||||
moveToCleanup :: Git.Repo -> Key -> Annex Bool
|
moveToCleanup :: Git.Repo -> Key -> Annex Bool
|
||||||
moveToCleanup remote key = do
|
moveToCleanup remote key = do
|
||||||
-- Update local location log; key is present there and missing here.
|
-- cleanup on the local side is the same as done for the drop subcommand
|
||||||
logStatus key ValueMissing
|
ok <- dropCleanup key
|
||||||
u <- getUUID remote
|
if (not ok)
|
||||||
liftIO $ logChange remote key u ValuePresent
|
then return False
|
||||||
-- Propigate location log to remote.
|
else do
|
||||||
error "TODO: update remote locationlog"
|
-- Record that the key is present on the remote.
|
||||||
return True
|
u <- getUUID remote
|
||||||
|
liftIO $ logChange remote key u ValuePresent
|
||||||
|
-- Propigate location log to remote.
|
||||||
|
error "TODO: update remote locationlog"
|
||||||
|
return True
|
||||||
|
|
||||||
{- Moves the content of an annexed file from another repository to the current
|
{- Moves the content of an annexed file from another repository to the current
|
||||||
- repository and updates locationlog information on both.
|
- repository and updates locationlog information on both.
|
||||||
|
@ -403,22 +406,28 @@ moveFromPerform file key = do
|
||||||
isthere <- Remotes.inAnnex remote key
|
isthere <- Remotes.inAnnex remote key
|
||||||
ishere <- inAnnex key
|
ishere <- inAnnex key
|
||||||
case (ishere, isthere) of
|
case (ishere, isthere) of
|
||||||
(_, Left err) -> error (show err)
|
(_, Left err) -> do
|
||||||
(_, Right False) -> return Nothing -- not in remote; fail
|
showNote $ show err
|
||||||
(False, Right True) -> moveit remote key
|
return Nothing
|
||||||
(True, Right True) -> removeit remote key
|
(_, Right False) -> do
|
||||||
where
|
showNote $ "not present in " ++ (Git.repoDescribe remote)
|
||||||
moveit remote key = do
|
return Nothing
|
||||||
|
(False, Right True) -> do
|
||||||
|
-- copy content from remote
|
||||||
ok <- getViaTmp key (Remotes.copyFromRemote remote key)
|
ok <- getViaTmp key (Remotes.copyFromRemote remote key)
|
||||||
if (ok)
|
if (ok)
|
||||||
then removeit remote key
|
then return $ Just $ moveFromCleanup remote key
|
||||||
else return Nothing -- fail
|
else return Nothing -- fail
|
||||||
removeit remote key = do
|
(True, Right True) -> do
|
||||||
error $ "TODO remove" ++ file
|
-- the content is already here, just remove from remote
|
||||||
return $ Just moveFromCleanup
|
return $ Just $ moveFromCleanup remote key
|
||||||
moveFromCleanup :: Annex Bool
|
moveFromCleanup :: Git.Repo -> Key -> Annex Bool
|
||||||
moveFromCleanup = do
|
moveFromCleanup remote key = do
|
||||||
error "update location logs"
|
Remotes.removeRemoteFile remote $ annexLocation remote key
|
||||||
|
-- Record that the key is not on the remote.
|
||||||
|
u <- getUUID remote
|
||||||
|
liftIO $ logChange remote key u ValueMissing
|
||||||
|
Remotes.updateRemoteLogStatus remote key
|
||||||
return True
|
return True
|
||||||
|
|
||||||
-- helpers
|
-- helpers
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
module LocationLog (
|
module LocationLog (
|
||||||
LogStatus(..),
|
LogStatus(..),
|
||||||
logChange,
|
logChange,
|
||||||
keyLocations
|
keyLocations,
|
||||||
|
logFile,
|
||||||
|
readLog
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Time.Clock.POSIX
|
import Data.Time.Clock.POSIX
|
||||||
|
|
|
@ -28,6 +28,9 @@ gitStateDir repo = (Git.workTree repo) ++ "/" ++ stateLoc
|
||||||
- <backend:fragment>
|
- <backend:fragment>
|
||||||
-
|
-
|
||||||
- That allows deriving the key and backend by looking at the symlink to it.
|
- That allows deriving the key and backend by looking at the symlink to it.
|
||||||
|
-
|
||||||
|
- Note that even if the repo is a bare repo, the annex is put in a .git
|
||||||
|
- sub
|
||||||
-}
|
-}
|
||||||
annexLocation :: Git.Repo -> Key -> FilePath
|
annexLocation :: Git.Repo -> Key -> FilePath
|
||||||
annexLocation r key =
|
annexLocation r key =
|
||||||
|
|
44
Remotes.hs
44
Remotes.hs
|
@ -7,7 +7,9 @@ module Remotes (
|
||||||
inAnnex,
|
inAnnex,
|
||||||
commandLineRemote,
|
commandLineRemote,
|
||||||
copyFromRemote,
|
copyFromRemote,
|
||||||
copyToRemote
|
copyToRemote,
|
||||||
|
removeRemoteFile,
|
||||||
|
updateRemoteLogStatus
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Exception
|
import Control.Exception
|
||||||
|
@ -16,8 +18,11 @@ import Control.Monad (filterM)
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import Data.String.Utils
|
import Data.String.Utils
|
||||||
import Data.Either.Utils
|
import Data.Either.Utils
|
||||||
|
import System.Cmd.Utils
|
||||||
|
import System.Directory
|
||||||
import List
|
import List
|
||||||
import Maybe
|
import Maybe
|
||||||
|
import IO (hPutStrLn)
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
import qualified GitRepo as Git
|
import qualified GitRepo as Git
|
||||||
|
@ -223,3 +228,40 @@ copyToRemote r key = do
|
||||||
location g = annexLocation g key
|
location g = annexLocation g key
|
||||||
sshlocation = (Git.urlHost r) ++ ":" ++ file
|
sshlocation = (Git.urlHost r) ++ ":" ++ file
|
||||||
file = error "TODO"
|
file = error "TODO"
|
||||||
|
|
||||||
|
{- Removes a file from a remote. -}
|
||||||
|
removeRemoteFile :: Git.Repo -> FilePath -> Annex ()
|
||||||
|
removeRemoteFile r file = do
|
||||||
|
if (not $ Git.repoIsUrl r)
|
||||||
|
then liftIO $ removeFile file
|
||||||
|
else if (Git.repoIsSsh r)
|
||||||
|
then do
|
||||||
|
ok <- liftIO $ boolSystem "ssh"
|
||||||
|
[Git.urlHost r, "rm -f " ++
|
||||||
|
(shellEscape file)]
|
||||||
|
if (ok)
|
||||||
|
then return ()
|
||||||
|
else error "failed to remove file from remote"
|
||||||
|
else error "removing file from non-ssh repo not supported"
|
||||||
|
|
||||||
|
{- Update's a remote's location log for a key, by merging the local
|
||||||
|
- location log into it. -}
|
||||||
|
updateRemoteLogStatus :: Git.Repo -> Key -> Annex ()
|
||||||
|
updateRemoteLogStatus r key = do
|
||||||
|
-- To merge, just append data to the remote's
|
||||||
|
-- log. Since the log is timestamped, the presumably newer
|
||||||
|
-- information from the local will superscede the older
|
||||||
|
-- information in the remote's log.
|
||||||
|
-- TODO: remote log locking
|
||||||
|
let mergecmd = "cat >> " ++ (shellEscape $ logFile r key) ++ " && " ++
|
||||||
|
"cd " ++ (shellEscape $ Git.workTree r) ++ " && " ++
|
||||||
|
"git add " ++ (shellEscape $ gitStateDir r)
|
||||||
|
let shellcmd = if (not $ Git.repoIsUrl r)
|
||||||
|
then pOpen WriteToPipe "sh" ["-c", mergecmd]
|
||||||
|
else if (Git.repoIsSsh r)
|
||||||
|
then pOpen WriteToPipe "ssh" [Git.urlHost r, mergecmd]
|
||||||
|
else error "updating non-ssh repo not supported"
|
||||||
|
g <- Annex.gitRepo
|
||||||
|
liftIO $ shellcmd $ \h -> do
|
||||||
|
lines <- readLog $ logFile g key
|
||||||
|
hPutStrLn h $ unlines $ map show lines
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue