module Propellor.Property.Rsync where
import Propellor.Base
import qualified Propellor.Property.Apt as Apt
type Src = FilePath
type Dest = FilePath
class RsyncParam p where
toRsync :: p -> String
filesUnder :: FilePath -> Pattern
filesUnder d = Pattern (d ++ "/*")
syncDir :: Src -> Dest -> Property NoInfo
syncDir = syncDirFiltered []
data Filter
= Include Pattern
| Exclude Pattern
| Protect Pattern
instance RsyncParam Filter where
toRsync (Include (Pattern p)) = "--include=" ++ p
toRsync (Exclude (Pattern p)) = "--exclude=" ++ p
toRsync (Protect (Pattern p)) = "--filter=P " ++ p
newtype Pattern = Pattern String
syncDirFiltered :: [Filter] -> Src -> Dest -> Property NoInfo
syncDirFiltered filters src dest = rsync $
[ "-av"
, addTrailingPathSeparator src
, addTrailingPathSeparator dest
, "--delete"
, "--delete-excluded"
, "--quiet"
] ++ map toRsync filters
rsync :: [String] -> Property NoInfo
rsync ps = cmdProperty "rsync" ps
`assume` MadeChange
`requires` Apt.installed ["rsync"]