2010-11-27 21:09:22 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010 Joey Hess <id@joeyh.name>
|
2010-11-27 21:09:22 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Copy where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Command.Move
|
2012-01-06 08:02:35 +00:00
|
|
|
import qualified Remote
|
2012-10-08 20:06:56 +00:00
|
|
|
import Annex.Wanted
|
2015-04-30 18:02:56 +00:00
|
|
|
import Annex.NumCopies
|
2010-11-27 21:09:22 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-07-30 17:33:35 +00:00
|
|
|
cmd = withGlobalOptions (jobsOption : annexedMatchingOptions) $
|
|
|
|
command "copy" SectionCommon
|
|
|
|
"copy content of files to/from another repository"
|
|
|
|
paramPaths (seek <--< optParser)
|
2015-07-09 19:23:14 +00:00
|
|
|
|
|
|
|
data CopyOptions = CopyOptions
|
|
|
|
{ moveOptions :: Command.Move.MoveOptions
|
|
|
|
, autoMode :: Bool
|
|
|
|
}
|
|
|
|
|
|
|
|
optParser :: CmdParamsDesc -> Parser CopyOptions
|
|
|
|
optParser desc = CopyOptions
|
|
|
|
<$> Command.Move.optParser desc
|
|
|
|
<*> parseAutoOption
|
|
|
|
|
|
|
|
instance DeferredParseClass CopyOptions where
|
|
|
|
finishParse v = CopyOptions
|
|
|
|
<$> finishParse (moveOptions v)
|
|
|
|
<*> pure (autoMode v)
|
|
|
|
|
|
|
|
seek :: CopyOptions -> CommandSeek
|
2015-11-06 17:41:26 +00:00
|
|
|
seek o = allowConcurrentOutput $
|
|
|
|
withKeyOptions (Command.Move.keyOptions $ moveOptions o) (autoMode o)
|
|
|
|
(Command.Move.startKey (moveOptions o) False)
|
|
|
|
(withFilesInGit $ whenAnnexed $ start o)
|
|
|
|
(Command.Move.moveFiles $ moveOptions o)
|
2011-09-15 19:27:45 +00:00
|
|
|
|
2012-10-08 20:06:56 +00:00
|
|
|
{- A copy is just a move that does not delete the source file.
|
2015-03-25 21:06:14 +00:00
|
|
|
- However, auto mode avoids unnecessary copies, and avoids getting or
|
2012-10-08 20:06:56 +00:00
|
|
|
- sending non-preferred content. -}
|
2015-07-09 19:23:14 +00:00
|
|
|
start :: CopyOptions -> FilePath -> Key -> CommandStart
|
|
|
|
start o file key = stopUnless shouldCopy $
|
|
|
|
Command.Move.start (moveOptions o) False file key
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2015-03-25 21:06:14 +00:00
|
|
|
shouldCopy
|
2015-07-09 19:23:14 +00:00
|
|
|
| autoMode o = want <||> numCopiesCheck file key (<)
|
2015-03-25 21:06:14 +00:00
|
|
|
| otherwise = return True
|
2015-07-09 19:23:14 +00:00
|
|
|
want = case Command.Move.fromToOptions (moveOptions o) of
|
2015-10-06 21:29:44 +00:00
|
|
|
ToRemote dest -> (Remote.uuid <$> getParsed dest) >>=
|
2015-07-09 19:23:14 +00:00
|
|
|
wantSend False (Just key) (Just file)
|
2015-10-06 21:29:44 +00:00
|
|
|
FromRemote _ ->
|
|
|
|
wantGet False (Just key) (Just file)
|