@@ -40,6 +40,8 @@ module Testnet.Start.Types
4040 , NodeConfiguration
4141 , NodeConfigurationYaml
4242 , mkConf
43+ , mkConfigAbs
44+ , mkConfig
4345 ) where
4446
4547import Cardano.Api hiding (cardanoEra )
@@ -58,6 +60,7 @@ import qualified Data.Text as Text
5860import Data.Word
5961import GHC.Stack
6062import qualified Network.HTTP.Simple as HTTP
63+ import System.Directory (createDirectory , doesDirectoryExist , makeAbsolute )
6164import System.FilePath (addTrailingPathSeparator )
6265
6366import 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.
279280mkConf :: (HasCallStack , MonadTest m ) => FilePath -> m Conf
280281mkConf 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"@
289308anyEraToString :: AnyCardanoEra -> String
290309anyEraToString (AnyCardanoEra e) = eraToString e
0 commit comments