summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Systemd.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Propellor/Property/Systemd.hs')
-rw-r--r--src/Propellor/Property/Systemd.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Propellor/Property/Systemd.hs b/src/Propellor/Property/Systemd.hs
index 39b4bd84..b983d9d8 100644
--- a/src/Propellor/Property/Systemd.hs
+++ b/src/Propellor/Property/Systemd.hs
@@ -13,6 +13,7 @@ module Propellor.Property.Systemd (
networkd,
journald,
logind,
+ escapePath,
-- * Configuration
installed,
Option,
@@ -58,7 +59,9 @@ import Utility.FileMode
import Utility.Split
import Data.List
+import Data.Char
import qualified Data.Map as M
+import Text.Printf
type ServiceName = String
@@ -459,3 +462,15 @@ bind p = containerCfg $ "--bind=" ++ toBind p
-- | Read-only mind mount.
bindRo :: Bindable p => p -> RevertableProperty (HasInfo + Linux) (HasInfo + Linux)
bindRo p = containerCfg $ "--bind-ro=" ++ toBind p
+
+-- | Escapes a path for inclusion in a systemd unit name,
+-- the same as systemd-escape does.
+escapePath :: FilePath -> String
+escapePath = concatMap escape
+ . dropWhile (== '/')
+ . reverse . dropWhile (== '/') . reverse
+ where
+ escape '/' = "-"
+ escape c
+ | (isAscii c || c == '_') = [c]
+ | otherwise = '\\' : printf "%x" c