summaryrefslogtreecommitdiff
path: root/src/Propellor/Property
diff options
context:
space:
mode:
authorSean Whitton2016-05-21 20:04:25 +0900
committerSean Whitton2016-05-21 20:04:25 +0900
commit10f3c2db21a4b5c53d2575977cc1228fb71c9bc8 (patch)
tree01cfc7e525dfd6034c57cf793e492ed65dd5f1f6 /src/Propellor/Property
parente01ff0ae7718fbddb5e81c3b4d967af90d9d64ba (diff)
generalise setting limit on ccache
Diffstat (limited to 'src/Propellor/Property')
-rw-r--r--src/Propellor/Property/Ccache.hs43
1 files changed, 32 insertions, 11 deletions
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"]