From 58f28b2a19ed193d68ce0b209f6f7f87726719de Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 19 Aug 2018 21:53:52 -0400 Subject: Systemd.escapePath function Useful when creating mount units. --- debian/changelog | 2 ++ src/Propellor/Property/Systemd.hs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) 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 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 -- cgit v1.2.3