use transfer stages for copy --from
authorJoey Hess <joeyh@joeyh.name>
Tue, 24 Jan 2023 18:03:26 +0000 (14:03 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 24 Jan 2023 18:07:49 +0000 (14:07 -0400)
See commit e04a9314392037e7b54a098f9709fc6040327411 for an explanation
of why move uses transfer stages for --from, but command stages for
--to. At the point of that commit, copy was actually already using
command stages for everything, so the commit was incorrect about
improving copy --to.

But, the same reasoning about --from applies to copy as to move; when
verification is not done incrementally, download and verification are
the main two stages. The cleanup stage for copy is even less work than
for move (it doesn't drop from the remote).

Sponsored-by: Dartmouth College's DANDI project
Command/Copy.hs
Command/Move.hs

index e53e5cdbe4ff0dd461ce9d0f62381f3ef26fc83f..5c9e97dceff5eca066450d00f9e278db2ae72580 100644 (file)
@@ -50,7 +50,7 @@ seek o = case fromToOptions o of
        Nothing -> giveup "Specify --from or --to"
 
 seek' :: CopyOptions -> FromToHereOptions -> CommandSeek
-seek' o fto = startConcurrend stages $ do
+seek' o fto = startConcurrency (Command.Move.stages fto) $ do
        case batchOption o of
                NoBatch -> withKeyOptions
                        (keyOptions o) (autoMode o) seeker
@@ -73,12 +73,6 @@ seek' o fto = startConcurrend stages $ do
                }
        keyaction = Command.Move.startKey fto Command.Move.RemoveNever
 
-       stages = case fto of
-               FromOrToRemote (FromRemote _) -> commandStages
-               FromOrToRemote (ToRemote _) -> commandStages
-               ToHere -> commandStages
-               FromRemoteToRemote _ _ -> transferStages
-
 {- A copy is just a move that does not delete the source file.
  - However, auto mode avoids unnecessary copies, and avoids getting or
  - sending non-preferred content. -}
index 23a319645d058d898dfe5f6509014be6269d2cb7..528e6ce22c002f02535d0545f03d64df12caad22 100644 (file)
@@ -65,7 +65,7 @@ seek o = case fromToOptions o of
        Nothing -> giveup "Specify --from or --to"
 
 seek' :: MoveOptions -> FromToHereOptions -> CommandSeek
-seek' o fto = startConcurrency stages $ do
+seek' o fto = startConcurrency (stages fto) $ do
        case batchOption o of
                NoBatch -> withKeyOptions (keyOptions o) False seeker
                        (commandAction . keyaction)
@@ -83,14 +83,15 @@ seek' o fto = startConcurrency stages $ do
                        FromRemoteToRemote _ _ -> Nothing
                , usesLocationLog = True
                }
-       stages = case fto of
-               FromOrToRemote (FromRemote _) -> transferStages
-               FromOrToRemote (ToRemote _) -> commandStages
-               ToHere -> transferStages
-               FromRemoteToRemote _ _ -> transferStages
        keyaction = startKey fto (removeWhen o)
        ww = WarnUnmatchLsFiles
 
+stages :: FromToHereOptions -> UsedStages
+stages (FromOrToRemote (FromRemote _)) = transferStages
+stages (FromOrToRemote (ToRemote _)) = commandStages
+stages ToHere = transferStages
+stages (FromRemoteToRemote _ _) = transferStages
+
 start :: FromToHereOptions -> RemoveWhen -> SeekInput -> RawFilePath -> Key -> CommandStart
 start fromto removewhen si f k = start' fromto removewhen afile si k ai
   where