diff options
| author | Sean Whitton <spwhitton@spwhitton.name> | 2016-05-22 09:32:05 +0900 |
|---|---|---|
| committer | Sean Whitton <spwhitton@spwhitton.name> | 2016-05-22 09:34:05 +0900 |
| commit | 52505a7d9f85e82fc2c50565f6646b441e0faf53 (patch) | |
| tree | 4b4811a0e981086202c5a997392cb958fd2c6cc4 /src/Propellor/Property/Ccache.hs | |
| parent | 8ed862f8239d5a5ec4cfa1e5dea24add38038ab1 (diff) | |
property to set the limits filled out
Diffstat (limited to 'src/Propellor/Property/Ccache.hs')
| -rw-r--r-- | src/Propellor/Property/Ccache.hs | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/Propellor/Property/Ccache.hs b/src/Propellor/Property/Ccache.hs index 692fea0f..8b6ddb5a 100644 --- a/src/Propellor/Property/Ccache.hs +++ b/src/Propellor/Property/Ccache.hs @@ -14,6 +14,7 @@ import qualified Propellor.Property.Apt as Apt import Utility.FileMode import Utility.DataUnits import System.Posix.Files +import Data.Either -- | Limits on the size of a ccache data Limit @@ -55,20 +56,33 @@ ccacheSizeUnits sz = filter (/= ' ') (roughSize cfgfileunits True sz) -- | Set limits on a given ccache. hasLimits :: FilePath -> Limit -> Property UnixLike -hasLimits = undefined +path `hasLimits` limit = property' ("limits set on ccache " ++ path) $ + \w -> if null errors + -- We invoke ccache itself to set the limits, so that it can handle + -- replacing old limits in the config file, duplicates etc. + then ensureProperty w $ + cmdPropertyEnv "ccache" params' [("CCACHE_DIR", path)] + `changesFile` (path </> "ccache.conf") + else sequence_ (errorMessage <$> errors) + >> return FailedChange + where + params = limitToParams limit + (errors, params') = partitionEithers params --- limitToParams :: Limit -> [String] --- limitToParams NoLimit = [] --- limitToParams (MaxSize s) = --- limitToParams (MaxFiles f) = --- limitToParams (l1 :+ l2) = limitToParams l1 <> limitToParams l2 +limitToParams :: Limit -> [Either String String] +limitToParams NoLimit = [] +limitToParams (MaxSize s) = case maxSizeParam s of + Just param -> [Right param] + Nothing -> [Left $ "unable to parse data size " ++ s] +limitToParams (MaxFiles f) = [Right $ "--max-files=" ++ show f] +limitToParams (l1 :+ l2) = limitToParams l1 <> limitToParams l2 -- | Configures a ccache in /var/cache for a group -- -- If you say -- -- > & (Group "foo") `Ccache.hasGroupCache` (Ccache.MaxSize "4G" --- <> Ccache.MaxFiles 10000) +-- > <> Ccache.MaxFiles 10000) -- -- you instruct propellor to create a ccache in /var/cache/ccache-foo owned and -- writeable by the foo group, with a maximum cache size of 4GB or 10000 files. |
