2014-03-18 16:55:08 +00:00
|
|
|
{- Rsync urls.
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-03-18 16:55:08 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
|
|
|
module Remote.Rsync.RsyncUrl where
|
|
|
|
|
|
|
|
import Types
|
|
|
|
import Locations
|
|
|
|
import Utility.Rsync
|
|
|
|
import Utility.SafeCommand
|
|
|
|
|
2015-01-28 19:55:17 +00:00
|
|
|
import Data.Default
|
2014-03-18 16:55:08 +00:00
|
|
|
import System.FilePath.Posix
|
|
|
|
#ifdef mingw32_HOST_OS
|
|
|
|
import Data.String.Utils
|
|
|
|
#endif
|
2015-01-28 20:51:40 +00:00
|
|
|
import Annex.DirHashes
|
2014-03-18 16:55:08 +00:00
|
|
|
|
|
|
|
type RsyncUrl = String
|
|
|
|
|
|
|
|
data RsyncOpts = RsyncOpts
|
|
|
|
{ rsyncUrl :: RsyncUrl
|
|
|
|
, rsyncOptions :: [CommandParam]
|
|
|
|
, rsyncUploadOptions :: [CommandParam]
|
|
|
|
, rsyncDownloadOptions :: [CommandParam]
|
|
|
|
, rsyncShellEscape :: Bool
|
|
|
|
}
|
|
|
|
|
|
|
|
rsyncEscape :: RsyncOpts -> RsyncUrl -> RsyncUrl
|
|
|
|
rsyncEscape o u
|
|
|
|
| rsyncShellEscape o && rsyncUrlIsShell (rsyncUrl o) = shellEscape u
|
|
|
|
| otherwise = u
|
|
|
|
|
|
|
|
rsyncUrls :: RsyncOpts -> Key -> [RsyncUrl]
|
2015-01-28 22:01:54 +00:00
|
|
|
rsyncUrls o k = map use dirHashes
|
2014-03-18 16:55:08 +00:00
|
|
|
where
|
|
|
|
use h = rsyncUrl o </> hash h </> rsyncEscape o (f </> f)
|
|
|
|
f = keyFile k
|
|
|
|
#ifndef mingw32_HOST_OS
|
2015-01-28 22:01:54 +00:00
|
|
|
hash h = h def k
|
2014-03-18 16:55:08 +00:00
|
|
|
#else
|
2015-01-29 17:46:57 +00:00
|
|
|
hash h = replace "\\" "/" (h def k)
|
2014-03-18 16:55:08 +00:00
|
|
|
#endif
|