2014-03-18 16:55:08 +00:00
|
|
|
{- Rsync urls.
|
|
|
|
-
|
2018-02-28 16:09:03 +00:00
|
|
|
- Copyright 2014-2018 Joey Hess <id@joeyh.name>
|
2014-03-18 16:55:08 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-03-18 16:55:08 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
|
|
|
module Remote.Rsync.RsyncUrl where
|
|
|
|
|
|
|
|
import Types
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Locations
|
2014-03-18 16:55:08 +00:00
|
|
|
import Utility.Rsync
|
|
|
|
import Utility.SafeCommand
|
2019-12-11 18:12:22 +00:00
|
|
|
import Utility.FileSystemEncoding
|
|
|
|
import Annex.DirHashes
|
2014-03-18 16:55:08 +00:00
|
|
|
#ifdef mingw32_HOST_OS
|
2017-05-16 03:32:17 +00:00
|
|
|
import Utility.Split
|
2014-03-18 16:55:08 +00:00
|
|
|
#endif
|
2019-12-11 18:12:22 +00:00
|
|
|
|
|
|
|
import Data.Default
|
|
|
|
import System.FilePath.Posix
|
2014-03-18 16:55:08 +00:00
|
|
|
|
|
|
|
type RsyncUrl = String
|
|
|
|
|
|
|
|
data RsyncOpts = RsyncOpts
|
|
|
|
{ rsyncUrl :: RsyncUrl
|
2019-06-13 15:09:55 +00:00
|
|
|
, rsyncOptions :: Annex [CommandParam]
|
|
|
|
, rsyncUploadOptions :: Annex [CommandParam]
|
|
|
|
, rsyncDownloadOptions :: Annex [CommandParam]
|
2014-03-18 16:55:08 +00:00
|
|
|
, rsyncShellEscape :: Bool
|
|
|
|
}
|
|
|
|
|
|
|
|
rsyncEscape :: RsyncOpts -> RsyncUrl -> RsyncUrl
|
|
|
|
rsyncEscape o u
|
|
|
|
| rsyncShellEscape o && rsyncUrlIsShell (rsyncUrl o) = shellEscape u
|
|
|
|
| otherwise = u
|
|
|
|
|
2018-02-28 16:09:03 +00:00
|
|
|
mkRsyncUrl :: RsyncOpts -> FilePath -> RsyncUrl
|
|
|
|
mkRsyncUrl o f = rsyncUrl o </> rsyncEscape o f
|
|
|
|
|
2014-03-18 16:55:08 +00:00
|
|
|
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
|
2019-12-11 18:12:22 +00:00
|
|
|
use h = rsyncUrl o </> fromRawFilePath (hash h) </> rsyncEscape o (f </> f)
|
2014-03-18 16:55:08 +00:00
|
|
|
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
|