diff options
Diffstat (limited to 'src/Propellor/Property.hs')
| -rw-r--r-- | src/Propellor/Property.hs | 20 |
1 files changed, 18 insertions, 2 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. -- |
