aboutsummaryrefslogtreecommitdiff
path: root/Remote/Rsync/RsyncUrl.hs
blob: a7a2ac8f6fbe4f4492475252fb60d7c4f71ed8fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{- Rsync urls.
 -
 - Copyright 2014 Joey Hess <id@joeyh.name>
 -
 - 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

import Data.Default
import System.FilePath.Posix
#ifdef mingw32_HOST_OS
import Data.String.Utils
#endif
import Annex.DirHashes

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]
rsyncUrls o k = map use dirHashes
  where
	use h = rsyncUrl o </> hash h </> rsyncEscape o (f </> f)
	f = keyFile k
#ifndef mingw32_HOST_OS
	hash h = h def k
#else
	hash h = replace "\\" "/" (h def k)
#endif