Skip to content

Commit

Permalink
Ignore scenario subdirs starting with underscore (#837)
Browse files Browse the repository at this point in the history
Such subdirectories can be used to e.g. organize `.sw` files, and will be ignored when recursively loading scenarios.

This resolves an issue we noticed while reviewing #835, which uses a subdirectory to hold multiple `.sw` files for a scenario and was generating a lot of spurious warnings.
  • Loading branch information
byorgey authored Nov 6, 2022
1 parent 29594ab commit e0a275f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Swarm/Game/ScenarioInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ loadScenarioDir em dir = do
<> ", using alphabetical order"
return Nothing
True -> Just . filter (not . null) . lines <$> sendIO (readFile orderFile)
fs <- sendIO $ keepYamlOrDirectory <$> listDirectory dir
fs <- sendIO $ keepYamlOrPublicDirectory <$> listDirectory dir

case morder of
Just order -> do
Expand All @@ -287,7 +287,11 @@ loadScenarioDir em dir = do
let morder' = filter (`elem` fs) <$> morder
SC morder' . M.fromList <$> mapM (\item -> (item,) <$> loadScenarioItem em (dir </> item)) fs
where
keepYamlOrDirectory = filter (\f -> takeExtensions f `elem` ["", ".yaml"])
-- Keep only files which are .yaml files or directories that start
-- with something other than an underscore.
keepYamlOrPublicDirectory =
filter
(\f -> takeExtensions f == ".yaml" || (takeExtensions f == "" && head f /= '_'))

-- | How to transform scenario path to save path.
scenarioPathToSavePath :: FilePath -> FilePath -> FilePath
Expand Down

0 comments on commit e0a275f

Please sign in to comment.