2010-12-31 17:39:30 +00:00
|
|
|
{- git-annex file copying with rsync
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module RsyncFile where
|
|
|
|
|
2010-12-31 23:09:17 +00:00
|
|
|
import Data.String.Utils
|
|
|
|
|
|
|
|
import Utility
|
|
|
|
|
|
|
|
{- Generates parameters to make rsync use a specified command as its remote
|
|
|
|
- shell. -}
|
2011-02-28 20:25:31 +00:00
|
|
|
rsyncShell :: [CommandParam] -> [CommandParam]
|
|
|
|
rsyncShell command = [Param "-e", Param $ unwords $ map escape (toCommand command)]
|
2010-12-31 23:09:17 +00:00
|
|
|
where
|
|
|
|
{- rsync requires some weird, non-shell like quoting in
|
|
|
|
- here. A doubled single quote inside the single quoted
|
|
|
|
- string is a single quote. -}
|
|
|
|
escape s = "'" ++ (join "''" $ split "'" s) ++ "'"
|
2010-12-31 17:39:30 +00:00
|
|
|
|
|
|
|
{- Runs rsync in server mode to send a file, and exits. -}
|
|
|
|
rsyncServerSend :: FilePath -> IO ()
|
2011-02-25 05:13:01 +00:00
|
|
|
rsyncServerSend file = rsyncExec $
|
2011-02-28 20:10:16 +00:00
|
|
|
rsyncServerParams ++ [Param "--sender", File file]
|
2010-12-31 17:39:30 +00:00
|
|
|
|
|
|
|
{- Runs rsync in server mode to receive a file. -}
|
|
|
|
rsyncServerReceive :: FilePath -> IO Bool
|
2011-02-28 20:10:16 +00:00
|
|
|
rsyncServerReceive file = rsync $ rsyncServerParams ++ [File file]
|
2010-12-31 17:39:30 +00:00
|
|
|
|
2011-02-28 20:25:31 +00:00
|
|
|
rsyncServerParams :: [CommandParam]
|
2010-12-31 17:39:30 +00:00
|
|
|
rsyncServerParams =
|
2011-02-28 20:10:16 +00:00
|
|
|
[ Param "--server"
|
|
|
|
-- preserve permissions
|
|
|
|
, Param "-p"
|
|
|
|
-- allow resuming of transfers of big files
|
|
|
|
, Param "--inplace"
|
|
|
|
-- other options rsync normally uses in server mode
|
|
|
|
, Params "-e.Lsf ."
|
2010-12-31 17:39:30 +00:00
|
|
|
]
|
|
|
|
|
2011-02-28 20:25:31 +00:00
|
|
|
rsync :: [CommandParam] -> IO Bool
|
2011-02-28 20:10:16 +00:00
|
|
|
rsync = boolSystem "rsync"
|
2010-12-31 17:39:30 +00:00
|
|
|
|
2011-02-28 20:25:31 +00:00
|
|
|
rsyncExec :: [CommandParam] -> IO ()
|
|
|
|
rsyncExec params = executeFile "rsync" True (toCommand params) Nothing
|