summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog2
-rw-r--r--src/Propellor/Property/Systemd.hs15
2 files changed, 17 insertions, 0 deletions
diff --git a/debian/changelog b/debian/changelog
index 080884ab..eff0efd3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,8 @@ propellor (5.5.0) UNRELEASED; urgency=medium
* letsencrypt': Pass --expand to support expanding the list of domains
* Split mailname property out of Hostname.sane, since bad mailname
guesses can lead to ugly surprises. (API change)
+ * Added Systemd.escapePath helper function useful when creating mount
+ units.
-- Joey Hess <id@joeyh.name> Thu, 09 Aug 2018 10:54:41 -0400
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