diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-10-26 15:38:29 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-10-26 15:38:29 -0400 |
| commit | 886705bf83f6351bc6740a07918f668cb8639197 (patch) | |
| tree | 9d68eb5a2447ab91ef967d55305cde3b3859b8a6 /src/Propellor/Property/File.hs | |
| parent | 103da27d1be08ed31574c9eb37632ac260963afe (diff) | |
| parent | 77e3a5d4d968f3567b1b8e62996e0e6c803ab642 (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Property/File.hs')
| -rw-r--r-- | src/Propellor/Property/File.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Propellor/Property/File.hs b/src/Propellor/Property/File.hs index 3476bad0..e29eceb8 100644 --- a/src/Propellor/Property/File.hs +++ b/src/Propellor/Property/File.hs @@ -5,6 +5,7 @@ import Utility.FileMode import System.Posix.Files import System.PosixCompat.Types +import System.Exit type Line = String @@ -134,6 +135,27 @@ link `isSymlinkedTo` (LinkTarget target) = property desc $ else makeChange updateLink updateLink = createSymbolicLink target `viaStableTmp` link +-- | Ensures that a file is a copy of another (regular) file. +isCopyOf :: FilePath -> FilePath -> Property NoInfo +f `isCopyOf` f' = property desc $ go =<< (liftIO $ tryIO $ getFileStatus f') + where + desc = f ++ " is copy of " ++ f' + go (Right stat) = if isRegularFile stat + then gocmp =<< (liftIO $ cmp) + else warningMessage (f' ++ " is not a regular file") >> + return FailedChange + go (Left e) = warningMessage (show e) >> return FailedChange + + cmp = safeSystem "cmp" [Param "-s", Param "--", File f, File f'] + gocmp ExitSuccess = noChange + gocmp (ExitFailure 1) = doit + gocmp _ = warningMessage "cmp failed" >> return FailedChange + + doit = makeChange $ copy f' `viaStableTmp` f + copy src dest = unlessM (runcp src dest) $ errorMessage "cp failed" + runcp src dest = boolSystem "cp" + [Param "--preserve=all", Param "--", File src, File dest] + -- | Ensures that a file/dir has the specified owner and group. ownerGroup :: FilePath -> User -> Group -> Property NoInfo ownerGroup f (User owner) (Group group) = property (f ++ " owner " ++ og) $ do |
