From 2c4d0c0acd0dd017e8f36d8a077a6f42ad5555ee Mon Sep 17 00:00:00 2001 From: Joseph Weston Date: Mon, 23 Jul 2018 13:48:45 +0200 Subject: [PATCH] lib: factor out logic for obtaining a list of files to include --- hledger-lib/Hledger/Read/JournalReader.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 204e93465..50fe9c902 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -190,23 +190,25 @@ includedirectivep :: MonadIO m => JournalParser m () includedirectivep = do string "include" lift (skipSome spacenonewline) - fileglob <- T.unpack <$> takeWhileP Nothing (/= '\n') -- don't consume newline yet + filename <- T.unpack <$> takeWhileP Nothing (/= '\n') -- don't consume newline yet parentpos <- getPosition curdir <- lift $ expandPath (takeDirectory $ sourceName parentpos) "" - `orRethrowIOError` (show parentpos ++ " locating " ++ fileglob) + `orRethrowIOError` (show parentpos ++ " locating " ++ filename) - filepaths <- if isLiteral (compile fileglob) - -- and globDir1 correctly handle case when 'fileglob' is absolute - then pure [curdir fileglob] - else liftIO $ globDir1 (compile fileglob) curdir + filepaths <- getFilePaths curdir filename forM_ filepaths $ parseChild parentpos void newline where + getFilePaths curdir fileglob = + if isLiteral (compile fileglob) + -- and globDir1 correctly handle case when 'fileglob' is absolute + then pure [curdir fileglob] + else liftIO $ globDir1 (compile fileglob) curdir parseChild parentpos filepath = do childInput <- lift $ readFilePortably filepath `orRethrowIOError` (show parentpos ++ " reading " ++ filepath)