summaryrefslogtreecommitdiff
path: root/src/Propellor/Property.hs
diff options
context:
space:
mode:
authorJoey Hess2015-12-05 15:48:03 -0400
committerJoey Hess2015-12-05 15:48:03 -0400
commitb816e40e2618a8932144bceb7c7039adc5c44c11 (patch)
treed128d9578764bc9b87d728370ffd4bc811e3b4d2 /src/Propellor/Property.hs
parentb15dd3010190700bc61a06b1a1d017b0500be28a (diff)
Added UncheckedProperty type, along with unchecked to indicate a Property needs its result checked, and checkResult and changesFile to check for changes.
Diffstat (limited to 'src/Propellor/Property.hs')
-rw-r--r--src/Propellor/Property.hs22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/Propellor/Property.hs b/src/Propellor/Property.hs
index 063e7814..f57fcaee 100644
--- a/src/Propellor/Property.hs
+++ b/src/Propellor/Property.hs
@@ -12,7 +12,6 @@ module Propellor.Property (
, check
, fallback
, trivial
- , changesFile
, revert
-- * Property descriptions
, describe
@@ -26,6 +25,12 @@ module Propellor.Property (
, noChange
, doNothing
, endAction
+ -- * Property result checking
+ , UncheckedProperty
+ , unchecked
+ , changesFile
+ , checkResult
+ , Checkable
) where
import System.Directory
@@ -37,6 +42,7 @@ import "mtl" Control.Monad.RWS.Strict
import System.Posix.Files
import Propellor.Types
+import Propellor.Types.ResultCheck
import Propellor.Info
import Propellor.Exception
import Utility.Exception
@@ -193,17 +199,13 @@ trivial p = adjustPropertySatisfy p $ \satisfy -> do
-- | Indicates that a Property may change a particular file. When the file
-- is modified, the property will return MadeChange instead of NoChange.
-changesFile :: Property i -> FilePath -> Property i
-changesFile p f = adjustPropertySatisfy p $ \satisfy -> do
- s <- getstat
- r <- satisfy
- if r == NoChange
- then do
- s' <- getstat
- return (if samestat s s' then NoChange else MadeChange)
- else return r
+changesFile :: Checkable p i => p i -> FilePath -> Property i
+changesFile p f = checkResult getstat comparestat p
where
getstat = liftIO $ catchMaybeIO $ getSymbolicLinkStatus f
+ comparestat oldstat = do
+ newstat <- getstat
+ return $ if samestat oldstat newstat then NoChange else MadeChange
samestat Nothing Nothing = True
samestat (Just a) (Just b) = and
-- everything except for atime