Skip to content

Commit 9ebf231

Browse files
committed
db-synthesizer: relax check whether a dir "looks like a ChainDB"
See the PR description
1 parent 756a79a commit 9ebf231

File tree

1 file changed

+11
-4
lines changed
  • ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBSynthesizer

1 file changed

+11
-4
lines changed

ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBSynthesizer/Run.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Cardano.Node.Types
1212
import Cardano.Tools.DBSynthesizer.Forging
1313
import Cardano.Tools.DBSynthesizer.Orphans ()
1414
import Cardano.Tools.DBSynthesizer.Types
15+
import Control.Monad (filterM)
1516
import Control.Monad.Trans.Except (ExceptT)
1617
import Control.Monad.Trans.Except.Extra (firstExceptT,
1718
handleIOExceptT, hoistEither, runExceptT)
@@ -20,6 +21,7 @@ import Data.Aeson as Aeson (FromJSON, Result (..), Value,
2021
eitherDecodeFileStrict', eitherDecodeStrict', fromJSON)
2122
import Data.Bool (bool)
2223
import Data.ByteString as BS (ByteString, readFile)
24+
import qualified Data.Set as Set
2325
import Ouroboros.Consensus.Cardano.Block
2426
import Ouroboros.Consensus.Cardano.Node
2527
import Ouroboros.Consensus.Config (TopLevelConfig, configStorage)
@@ -170,11 +172,12 @@ preOpenChainDB :: DBSynthesizerOpenMode -> FilePath -> IO ()
170172
preOpenChainDB mode db =
171173
doesDirectoryExist db >>= bool create checkMode
172174
where
173-
checkIsDB ls = length ls <= 3 && all (`elem` ["immutable", "ledger", "volatile"]) ls
175+
checkIsDB ls = Set.fromList ls `Set.isSubsetOf` chainDBDirs
176+
chainDBDirs = Set.fromList ["immutable", "ledger", "volatile", "gsm"]
174177
loc = "preOpenChainDB: '" ++ db ++ "'"
175178
create = createDirectoryIfMissing True db
176179
checkMode = do
177-
isChainDB <- checkIsDB <$> listDirectory db
180+
isChainDB <- checkIsDB <$> listSubdirectories db
178181
case mode of
179182
OpenCreate ->
180183
fail $ loc ++ " already exists. Use -f to overwrite or -a to append."
@@ -184,5 +187,9 @@ preOpenChainDB mode db =
184187
removePathForcibly db >> create
185188
_ ->
186189
fail $ loc ++ " is non-empty and does not look like a ChainDB"
187-
<> " (i.e. its entries are not exactly 'immutable'/'ledger'/'volatile')."
188-
<> " Aborting."
190+
<> " (i.e. it contains directories other than"
191+
<> " 'immutable'/'ledger'/'volatile'/'gsm'). Aborting."
192+
193+
listSubdirectories path = filterM isDir =<< listDirectory path
194+
where
195+
isDir p = doesDirectoryExist (path </> p)

0 commit comments

Comments
 (0)