Skip to content

Commit 4de166b

Browse files
committed
Implement mkConfig and mkConfigAbs
1 parent 0216ae2 commit 4de166b

File tree

1 file changed

+22
-3
lines changed
  • cardano-testnet/src/Testnet/Start

1 file changed

+22
-3
lines changed

cardano-testnet/src/Testnet/Start/Types.hs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ module Testnet.Start.Types
4040
, NodeConfiguration
4141
, NodeConfigurationYaml
4242
, mkConf
43+
, mkConfigAbs
44+
, mkConfig
4345
) where
4446

4547
import Cardano.Api hiding (cardanoEra)
@@ -58,6 +60,7 @@ import qualified Data.Text as Text
5860
import Data.Word
5961
import GHC.Stack
6062
import qualified Network.HTTP.Simple as HTTP
63+
import System.Directory (createDirectory, doesDirectoryExist, makeAbsolute)
6164
import System.FilePath (addTrailingPathSeparator)
6265

6366
import Testnet.Filepath
@@ -273,18 +276,34 @@ data Conf = Conf
273276
, updateTimestamps :: UpdateTimestamps
274277
} deriving (Eq, Show)
275278

276-
-- | Create a 'Conf' from a temporary absolute path, with Genesis Hashes enabled
277-
-- and updating time stamps disabled.
278279
-- Logs the argument in the test.
279280
mkConf :: (HasCallStack, MonadTest m) => FilePath -> m Conf
280281
mkConf tempAbsPath' = withFrozenCallStack $ do
281282
H.note_ tempAbsPath'
282-
pure $ Conf
283+
pure $ mkConfig tempAbsPath'
284+
285+
-- | Create a 'Conf' from a temporary absolute path, with Genesis Hashes enabled
286+
-- and updating time stamps disabled.
287+
mkConfig :: FilePath -> Conf
288+
mkConfig tempAbsPath' =
289+
Conf
283290
{ genesisHashesPolicy = WithHashes
284291
, tempAbsPath = TmpAbsolutePath (addTrailingPathSeparator tempAbsPath')
285292
, updateTimestamps = DontUpdateTimestamps
286293
}
287294

295+
mkConfigAbs :: FilePath -> IO Conf
296+
mkConfigAbs userOutputDir = do
297+
absUserOutputDir <- makeAbsolute userOutputDir
298+
dirExists <- doesDirectoryExist absUserOutputDir
299+
let conf = mkConfig absUserOutputDir
300+
if dirExists then
301+
-- Happens when the environment has previously been created by the user
302+
return conf
303+
else do
304+
createDirectory absUserOutputDir
305+
return conf
306+
288307
-- | @anyEraToString (AnyCardanoEra ByronEra)@ returns @"byron"@
289308
anyEraToString :: AnyCardanoEra -> String
290309
anyEraToString (AnyCardanoEra e) = eraToString e

0 commit comments

Comments
 (0)