-
Notifications
You must be signed in to change notification settings - Fork 753
Expand file tree
/
Copy pathFilepath.hs
More file actions
52 lines (40 loc) · 1.49 KB
/
Filepath.hs
File metadata and controls
52 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
module Testnet.Filepath
( TmpAbsolutePath(..)
, makeLogDir
, makeSocketDir
, makeSprocket
, makeTmpBaseAbsPath
) where
import Prelude
import Data.String (IsString (..))
import System.FilePath
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
import RIO (Display (..))
makeSprocket
:: TmpAbsolutePath
-> String -- ^ node name
-> Sprocket
makeSprocket tmpAbsPath node
= Sprocket (makeTmpBaseAbsPath tmpAbsPath) (makeSocketDir tmpAbsPath </> node)
-- TODO rename me: since the introduction of --output-dir in the cardano-testnet
-- executable, this is a directory that can persist after the test ends.
-- Temporary path used at runtime
newtype TmpAbsolutePath = TmpAbsolutePath
{ unTmpAbsPath :: FilePath
} deriving (Eq, Show, IsString)
instance Display TmpAbsolutePath where
textDisplay = fromString . unTmpAbsPath
makeSocketDir :: TmpAbsolutePath -> FilePath
makeSocketDir (TmpAbsolutePath fp) =
let relPath = makeRelative (takeDirectory fp) fp
in if relPath == "."
then "socket"
else relPath </> "socket"
makeTmpBaseAbsPath :: TmpAbsolutePath -> FilePath
makeTmpBaseAbsPath (TmpAbsolutePath fp) = addTrailingPathSeparator $ takeDirectory fp
makeLogDir :: TmpAbsolutePath -> FilePath
makeLogDir (TmpAbsolutePath fp) = addTrailingPathSeparator $ fp </> "logs"