From 35b91efc665b5f20f6d82046dfce818be669c8a3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 6 Dec 2015 00:21:32 -0400 Subject: setting the same sasl password updates the mtime of the file, but the contents remain the same Don't much like using Data.Hash.MD5, but it's available in dependencies and pulling in a real hash library would be overkill. And md5 is a perfectly ok hash to use here. --- src/Propellor/Property.hs | 20 ++++++++++++++++++-- src/Propellor/Property/Postfix.hs | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Propellor/Property.hs b/src/Propellor/Property.hs index 2976acf1..c58cc9fe 100644 --- a/src/Propellor/Property.hs +++ b/src/Propellor/Property.hs @@ -28,6 +28,7 @@ module Propellor.Property ( , UncheckedProperty , unchecked , changesFile + , changesFileContent , checkResult , Checkable , assume @@ -36,10 +37,12 @@ module Propellor.Property ( import System.Directory import System.FilePath import Control.Monad +import Control.Applicative import Data.Monoid import Control.Monad.IfElse import "mtl" Control.Monad.RWS.Strict import System.Posix.Files +import qualified Data.Hash.MD5 as MD5 import Propellor.Types import Propellor.Types.ResultCheck @@ -47,6 +50,7 @@ import Propellor.Info import Propellor.Exception import Utility.Exception import Utility.Monad +import Utility.Misc -- | Constructs a Property, from a description and an action to run to -- ensure the Property is met. @@ -185,11 +189,12 @@ fallback = combineWith combiner revertcombiner revertcombiner = (<>) -- | Indicates that a Property may change a particular file. When the file --- is modified, the property will return MadeChange instead of NoChange. +-- is modified in any way (including changing its permissions or mtime), +-- the property will return MadeChange instead of NoChange. changesFile :: Checkable p i => p i -> FilePath -> Property i changesFile p f = checkResult getstat comparestat p where - getstat = liftIO $ catchMaybeIO $ getSymbolicLinkStatus f + getstat = catchMaybeIO $ getSymbolicLinkStatus f comparestat oldstat = do newstat <- getstat return $ if samestat oldstat newstat then NoChange else MadeChange @@ -214,6 +219,17 @@ changesFile p f = checkResult getstat comparestat p ] samestat _ _ = False +-- | Like `changesFile`, but compares the content of the file. +-- Changes to mtime etc that do not change file content are treated as +-- NoChange. +changesFileContent :: Checkable p i => p i -> FilePath -> Property i +changesFileContent p f = checkResult getmd5 comparemd5 p + where + getmd5 = catchMaybeIO $ MD5.md5 . MD5.Str <$> readFileStrictAnyEncoding f + comparemd5 oldmd5 = do + newmd5 <- getmd5 + return $ if oldmd5 == newmd5 then NoChange else MadeChange + -- | Makes a property that is satisfied differently depending on the host's -- operating system. -- diff --git a/src/Propellor/Property/Postfix.hs b/src/Propellor/Property/Postfix.hs index 91a02927..bcb9fb30 100644 --- a/src/Propellor/Property/Postfix.hs +++ b/src/Propellor/Property/Postfix.hs @@ -170,7 +170,7 @@ saslAuthdInstalled = setupdaemon -- -- The password is taken from the privdata. saslPasswdSet :: Domain -> User -> Property HasInfo -saslPasswdSet domain (User user) = go `changesFile` "/etc/sasldb2" +saslPasswdSet domain (User user) = go `changesFileContent` "/etc/sasldb2" where go = withPrivData src ctx $ \getpw -> property desc $ getpw $ \pw -> liftIO $ -- cgit v1.2.3