From 10f3c2db21a4b5c53d2575977cc1228fb71c9bc8 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 21 May 2016 20:04:25 +0900 Subject: generalise setting limit on ccache --- src/Propellor/Property/Ccache.hs | 43 ++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'src/Propellor/Property/Ccache.hs') diff --git a/src/Propellor/Property/Ccache.hs b/src/Propellor/Property/Ccache.hs index 6ee796f0..d9b2e458 100644 --- a/src/Propellor/Property/Ccache.hs +++ b/src/Propellor/Property/Ccache.hs @@ -9,31 +9,52 @@ import qualified Propellor.Property.Apt as Apt import Utility.FileMode import System.Posix.Files +-- | Limits on the size of a ccache +data CcacheLimit + -- | The maximum size of the cache, as a string such as "4G" + -- + -- See ccache(1) for more on the size specification. + = MaxSize String + -- | The maximum number of files in the cache + | MaxFiles Int + -- | A cache with no limit specified + | NoLimit + -- | Configures a ccache in /var/cache for a group -- -- If you say -- --- > & (Group "foo") `Ccache.hasGroupCache` "4G" +-- > & (Group "foo") `Ccache.hasGroupCache` (Ccache.MaxSize "4g") -- -- 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. See ccache(1) --- for size specification. -hasGroupCache :: Group -> String -> RevertableProperty DebianLike UnixLike -group@(Group g) `hasGroupCache` size = (make `requires` installed) delete +-- writeable by the foo group, with a maximum cache size of 4GB. +-- +-- It is safe to specify this property more than once for a given group if you +-- wish to limit both the maximum size of the cache and the maximum number of +-- files in the cache. However, setting only one of these two limits is +-- generally sufficient. +hasGroupCache :: Group -> CcacheLimit -> RevertableProperty DebianLike UnixLike +group@(Group g) `hasGroupCache` limit = (make `requires` installed) delete where - path = "/var/cache/ccache-" ++ g - make = check (not <$> doesDirectoryExist path) $ - propertyList ("ccache for " ++ g ++ " exists") $ props + make = propertyList ("ccache for " ++ g ++ " exists") $ props & File.dirExists path & File.ownerGroup path (User "root") group & File.mode path (combineModes $ readModes ++ executeModes - ++ [ownerWriteMode, groupWriteMode]) - & cmdProperty "ccache" ["--max-size", size] - `assume` MadeChange + ++ [ownerWriteMode, groupWriteMode]) + & case limit of + NoLimit -> doNothing + MaxSize s -> setSizeLimit s + MaxFiles f -> setFileLimit (show f) + delete = check (doesDirectoryExist path) $ cmdProperty "rm" ["-r", path] `assume` MadeChange `describe` ("ccache for " ++ g ++ " does not exist") + setSizeLimit s = conf `File.containsLine` ("max_size = " ++ s) + setFileLimit f = conf `File.containsLine` ("max_files = " ++ f) + path = "/var/cache/ccache-" ++ g + conf = path "ccache.conf" + installed :: Property DebianLike installed = Apt.installed ["ccache"] -- cgit v1.2.3