summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-30 19:05:51 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-30 19:05:51 -0400
commit7ad60a109ab957499a45ac93697a86a5633bf96d (patch)
tree72eedfec2cef09b5ede9bbc8db4e0c566cd5e3c3
parent883395c399a0996d825711c6d8f29aa49ed07a69 (diff)
minor refactoring
-rw-r--r--Command/RecvKey.hs6
-rw-r--r--Command/SendKey.hs6
-rw-r--r--Utility/Rsync.hs14
3 files changed, 10 insertions, 16 deletions
diff --git a/Command/RecvKey.hs b/Command/RecvKey.hs
index a1c6093e8..041e104a7 100644
--- a/Command/RecvKey.hs
+++ b/Command/RecvKey.hs
@@ -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
diff --git a/Command/SendKey.hs b/Command/SendKey.hs
index d0e89aef9..afd1ac1e0 100644
--- a/Command/SendKey.hs
+++ b/Command/SendKey.hs
@@ -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)
diff --git a/Utility/Rsync.hs b/Utility/Rsync.hs
index 41eb53c21..a36c6076f 100644
--- a/Utility/Rsync.hs
+++ b/Utility/Rsync.hs
@@ -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) ""