summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Propellor/Property/File.hs10
-rw-r--r--src/Propellor/Property/Nginx.hs12
-rw-r--r--src/Propellor/Property/Prosody.hs8
-rw-r--r--src/Propellor/Property/Uwsgi.hs12
4 files changed, 14 insertions, 28 deletions
diff --git a/src/Propellor/Property/File.hs b/src/Propellor/Property/File.hs
index 07ace24b..08fdc780 100644
--- a/src/Propellor/Property/File.hs
+++ b/src/Propellor/Property/File.hs
@@ -97,14 +97,14 @@ dirExists :: FilePath -> Property NoInfo
dirExists d = check (not <$> doesDirectoryExist d) $ property (d ++ " exists") $
makeChange $ createDirectoryIfMissing True d
+-- | The location that a symbolic link points to.
+newtype LinkTarget = LinkTarget FilePath
+
-- | Creates or atomically updates a symbolic link.
--
--- The first parameter is what the link should point to.
---
--- The second parameter is the name of the symbolic link to create.
-- Does not overwrite regular files or directories.
-isSymlinkedTo :: FilePath -> FilePath -> Property NoInfo
-link `isSymlinkedTo` target = property desc $
+isSymlinkedTo :: FilePath -> LinkTarget -> Property NoInfo
+link `isSymlinkedTo` (LinkTarget target) = property desc $
go =<< (liftIO $ tryIO $ getSymbolicLinkStatus link)
where
desc = link ++ " is symlinked to " ++ target
diff --git a/src/Propellor/Property/Nginx.hs b/src/Propellor/Property/Nginx.hs
index 1bd285c7..c9b4d8fd 100644
--- a/src/Propellor/Property/Nginx.hs
+++ b/src/Propellor/Property/Nginx.hs
@@ -6,23 +6,17 @@ import Propellor.Base
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service
-import System.Posix.Files
type ConfigFile = [String]
siteEnabled :: HostName -> ConfigFile -> RevertableProperty
siteEnabled hn cf = enable <!> disable
where
- enable = check test prop
+ enable = siteVal hn `File.isSymlinkedTo` siteValRelativeCfg hn
`describe` ("nginx site enabled " ++ hn)
`requires` siteAvailable hn cf
`requires` installed
`onChange` reloaded
- where
- test = not <$> doesFileExist (siteVal hn)
- prop = dir `File.isSymlinkedTo` target
- target = siteValRelativeCfg hn
- dir = siteVal hn
disable = trivial $ File.notPresent (siteVal hn)
`describe` ("nginx site disable" ++ hn)
`requires` installed
@@ -40,8 +34,8 @@ siteCfg hn = "/etc/nginx/sites-available/" ++ hn
siteVal :: HostName -> FilePath
siteVal hn = "/etc/nginx/sites-enabled/" ++ hn
-siteValRelativeCfg :: HostName -> FilePath
-siteValRelativeCfg hn = "../sites-available/" ++ hn
+siteValRelativeCfg :: HostName -> File.LinkTarget
+siteValRelativeCfg hn = File.LinkTarget ("../sites-available/" ++ hn)
installed :: Property NoInfo
installed = Apt.installed ["nginx"]
diff --git a/src/Propellor/Property/Prosody.hs b/src/Propellor/Property/Prosody.hs
index 7dbfb1e1..0e379e63 100644
--- a/src/Propellor/Property/Prosody.hs
+++ b/src/Propellor/Property/Prosody.hs
@@ -6,7 +6,6 @@ import Propellor.Base
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service
-import System.Posix.Files
type ConfigFile = [String]
@@ -15,17 +14,16 @@ type Conf = String
confEnabled :: Conf -> ConfigFile -> RevertableProperty
confEnabled conf cf = enable <!> disable
where
- enable = check test prop
+ enable = dir `File.isSymlinkedTo` target
`describe` ("prosody conf enabled " ++ conf)
`requires` confAvailable conf cf
`requires` installed
`onChange` reloaded
where
- test = not <$> doesFileExist (confValPath conf)
- prop = dir `File.isSymlinkedTo` target
target = confValRelativePath conf
dir = confValPath conf
- confValRelativePath conf' = "../conf.avail" </> conf' <.> "cfg.lua"
+ confValRelativePath conf' = File.LinkTarget $
+ "../conf.avail" </> conf' <.> "cfg.lua"
disable = trivial $ File.notPresent (confValPath conf)
`describe` ("prosody conf disabled " ++ conf)
`requires` installed
diff --git a/src/Propellor/Property/Uwsgi.hs b/src/Propellor/Property/Uwsgi.hs
index c6ae880b..7de1a85a 100644
--- a/src/Propellor/Property/Uwsgi.hs
+++ b/src/Propellor/Property/Uwsgi.hs
@@ -6,7 +6,6 @@ import Propellor.Base
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service
-import System.Posix.Files
type ConfigFile = [String]
@@ -15,16 +14,11 @@ type AppName = String
appEnabled :: AppName -> ConfigFile -> RevertableProperty
appEnabled an cf = enable <!> disable
where
- enable = check test prop
+ enable = appVal an `File.isSymlinkedTo` appValRelativeCfg an
`describe` ("uwsgi app enabled " ++ an)
`requires` appAvailable an cf
`requires` installed
`onChange` reloaded
- where
- test = not <$> doesFileExist (appVal an)
- prop = dir `File.isSymlinkedTo` target
- target = appValRelativeCfg an
- dir = appVal an
disable = trivial $ File.notPresent (appVal an)
`describe` ("uwsgi app disable" ++ an)
`requires` installed
@@ -42,8 +36,8 @@ appCfg an = "/etc/uwsgi/apps-available/" ++ an
appVal :: AppName -> FilePath
appVal an = "/etc/uwsgi/apps-enabled/" ++ an
-appValRelativeCfg :: AppName -> FilePath
-appValRelativeCfg an = "../apps-available/" ++ an
+appValRelativeCfg :: AppName -> File.LinkTarget
+appValRelativeCfg an = File.LinkTarget $ "../apps-available/" ++ an
installed :: Property NoInfo
installed = Apt.installed ["uwsgi"]