Commit 37904802 authored by Iustin Pop's avatar Iustin Pop

Change keyToFilename/readSSconfFile interaction

Currently, keyToFilename uses itself the default config path. In the
light of making that an function in the IO monad, let's remove the
"default" path functionality from this function and make it always
require the config path; its caller, readSSConfFile, can then do the
maybe/default path change.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent d66aa238
......@@ -43,7 +43,7 @@ $(genArbitrary ''Ssconf.SSKey)
prop_filename :: Ssconf.SSKey -> Property
prop_filename key =
printTestCase "Key doesn't start with correct prefix" $
Ssconf.sSFilePrefix `isPrefixOf` Ssconf.keyToFilename (Just "") key
Ssconf.sSFilePrefix `isPrefixOf` Ssconf.keyToFilename "" key
testSuite "Ssconf"
[ 'prop_filename
......
......@@ -83,11 +83,11 @@ $(declareSADT "SSKey"
])
-- | Convert a ssconf key into a (full) file path.
keyToFilename :: Maybe FilePath -- ^ Optional config path override
-> SSKey -- ^ ssconf key
-> FilePath
keyToFilename optpath key = fromMaybe Path.dataDir optpath </>
sSFilePrefix ++ sSKeyToRaw key
keyToFilename :: FilePath -- ^ Config path root
-> SSKey -- ^ Ssconf key
-> FilePath -- ^ Full file name
keyToFilename cfgpath key = do
cfgpath </> sSFilePrefix ++ sSKeyToRaw key
-- | Runs an IO action while transforming any error into 'Bad'
-- values. It also accepts an optional value to use in case the error
......@@ -111,7 +111,8 @@ readSSConfFile :: Maybe FilePath -- ^ Optional config path override
-> SSKey -- ^ Desired ssconf key
-> IO (Result String)
readSSConfFile optpath def key = do
result <- catchIOErrors def . readFile . keyToFilename optpath $ key
result <- catchIOErrors def . readFile .
keyToFilename (fromMaybe Path.dataDir optpath) $ key
return (liftM (take maxFileSize) result)
-- | Strip space characthers (including newline). As this is
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment