{-# LANGUAGE LambdaCase #-}
module Test.Cardano.Mirror (
mainnetEpochFiles,
) where
import Cardano.Prelude
import System.Directory (doesDirectoryExist, getDirectoryContents)
import System.Environment (lookupEnv)
import System.FilePath (isExtensionOf, (</>))
mainnetEpochFiles :: IO [FilePath]
mainnetEpochFiles :: IO [String]
mainnetEpochFiles =
String -> IO (Maybe String)
lookupEnv String
"CARDANO_MAINNET_MIRROR" IO (Maybe String) -> (Maybe String -> IO [String]) -> IO [String]
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Maybe String
Nothing -> do
String -> IO ()
forall a (m :: * -> *). (Print a, MonadIO m) => a -> m ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn String
"mainnetEpochFiles: CARDANO_MAINNET_MIRROR variable is not set"
IO [String]
forall a. IO a
exitFailure
Just String
fpath -> do
exists <- String -> IO Bool
doesDirectoryExist String
fpath
if exists
then
sort
. fmap (fpath </>)
. filter ("epoch" `isExtensionOf`)
<$> getDirectoryContents fpath
else do
putStrLn
$ "mainnetEpochFiles: directory '"
++ fpath
++ "' does not exist."
exitFailure