minor refactoring
authorJoey Hess <joey@kitenet.net>
Sat, 30 Mar 2013 23:05:51 +0000 (19:05 -0400)
committerJoey Hess <joey@kitenet.net>
Sat, 30 Mar 2013 23:05:51 +0000 (19:05 -0400)
Command/RecvKey.hs
Command/SendKey.hs
Utility/Rsync.hs

index a1c6093e84219d87db1b8bd5c29783d3c0effcdb..041e104a75080faaff983cf4df890f5cd9d0ade3 100644 (file)
@@ -20,8 +20,6 @@ import qualified Types.Key
 import qualified Types.Backend
 import qualified Backend
 
-import System.Console.GetOpt
-
 def :: [Command]
 def = [noCommit $ command "recvkey" paramKey seek
        SectionPlumbing "runs rsync in server mode to receive content"]
@@ -44,8 +42,8 @@ start key = ifM (inAnnex key)
        )
   where
        go tmp = do
-               (opts,_,_) <- getOpt Permute rsyncSafeOptions <$>
-                               maybe [] words <$> getField "RsyncOptions"
+               opts <- filterRsyncSafeOptions . maybe [] words
+                       <$> getField "RsyncOptions"
                ifM (liftIO $ rsyncServerReceive (map Param opts) tmp)
                        ( ifM (isJust <$> Fields.getField Fields.direct)
                                ( directcheck tmp
index d0e89aef97fbbee22bd49ef24d889ab6fb6e0d3f..afd1ac1e0163a93d5668ee4c4c61e606d0f2595c 100644 (file)
@@ -16,8 +16,6 @@ import Logs.Transfer
 import qualified Fields
 import Utility.Metered
 
-import System.Console.GetOpt
-
 def :: [Command]
 def = [noCommit $ command "sendkey" paramKey seek
        SectionPlumbing "runs rsync in server mode to send content"]
@@ -27,8 +25,8 @@ seek = [withKeys start]
 
 start :: Key -> CommandStart
 start key = do
-       (opts,_,_) <- getOpt Permute rsyncSafeOptions <$>
-                       maybe [] words <$> getField "RsyncOptions"
+       opts <- filterRsyncSafeOptions . maybe [] words
+               <$> getField "RsyncOptions"
        ifM (inAnnex key)
                ( fieldTransfer Upload key $ \_p ->
                        sendAnnex key rollback $ liftIO . rsyncServerSend (map Param opts)
index 41eb53c212693ff7ab164e7a8b49bc0dc653811f..a36c6076f6195f9b332a16c2ce11e2fe946cf89b 100644 (file)
@@ -12,6 +12,7 @@ import Utility.Metered
 
 import Data.Char
 import System.Console.GetOpt
+import Data.Tuple.Utils
 
 {- Generates parameters to make rsync use a specified command as its remote
  - shell. -}
@@ -130,13 +131,10 @@ parseRsyncProgress = go [] . reverse . progresschunks
                (_, []) -> Nothing
                (b, _) -> readish b
 
-{- Rsync options that are safe to pass to rsync in server mode, without
- - causing it to eg, expose files.
- -
- - Note: Ensure that when calling getopt, the first component of the
- - output is a subset of the input.
- -}
-rsyncSafeOptions :: [OptDescr String]
-rsyncSafeOptions = [ Option [] ["bwlimit"] (reqArgLong "bwlimit") "" ]
+{- Filters options to those that are safe to pass to rsync in server mode,
+ - without causing it to eg, expose files. -}
+filterRsyncSafeOptions :: [String] -> [String]
+filterRsyncSafeOptions = fst3 . getOpt Permute
+       [ Option [] ["bwlimit"] (reqArgLong "bwlimit") "" ]
   where
        reqArgLong x = ReqArg (\v -> "--" ++ x ++ "=" ++ v) ""