lib: more thorough journal reloading
Reloading a journal should now reload all included files as well.
This commit is contained in:
parent
a4dc094be3
commit
9a424d77fc
@ -105,9 +105,9 @@ readJournalFile :: Maybe StorageFormat -> Maybe FilePath -> Bool -> FilePath ->
|
|||||||
readJournalFile format rulesfile assrt f = readJournalFiles format rulesfile assrt [f]
|
readJournalFile format rulesfile assrt f = readJournalFiles format rulesfile assrt [f]
|
||||||
|
|
||||||
readJournalFiles :: Maybe StorageFormat -> Maybe FilePath -> Bool -> [FilePath] -> IO (Either String Journal)
|
readJournalFiles :: Maybe StorageFormat -> Maybe FilePath -> Bool -> [FilePath] -> IO (Either String Journal)
|
||||||
readJournalFiles format rulesfile assrt f = do
|
readJournalFiles format rulesfile assrt fs = do
|
||||||
contents <- fmap concat $ mapM readFileAnyNewline f
|
contents <- fmap concat $ mapM readFileAnyNewline fs
|
||||||
readJournal format rulesfile assrt (listToMaybe f) contents
|
readJournal format rulesfile assrt (listToMaybe fs) contents
|
||||||
where
|
where
|
||||||
readFileAnyNewline f = do
|
readFileAnyNewline f = do
|
||||||
requireJournalFileExists f
|
requireJournalFileExists f
|
||||||
|
|||||||
@ -69,8 +69,8 @@ withJournalDo opts cmd = do
|
|||||||
-- it's stdin, or it doesn't exist and we are adding. We read it strictly
|
-- it's stdin, or it doesn't exist and we are adding. We read it strictly
|
||||||
-- to let the add command work.
|
-- to let the add command work.
|
||||||
rulespath <- rulesFilePathFromOpts opts
|
rulespath <- rulesFilePathFromOpts opts
|
||||||
journalpath <- journalFilePathFromOpts opts
|
journalpaths <- journalFilePathFromOpts opts
|
||||||
ej <- readJournalFiles Nothing rulespath (not $ ignore_assertions_ opts) journalpath
|
ej <- readJournalFiles Nothing rulespath (not $ ignore_assertions_ opts) journalpaths
|
||||||
either error' (cmd opts . journalApplyAliases (aliasesFromOpts opts)) ej
|
either error' (cmd opts . journalApplyAliases (aliasesFromOpts opts)) ej
|
||||||
|
|
||||||
-- | Write some output to stdout or to a file selected by --output-file.
|
-- | Write some output to stdout or to a file selected by --output-file.
|
||||||
@ -83,17 +83,21 @@ writeOutput opts s = do
|
|||||||
-- readJournalWithOpts :: CliOpts -> String -> IO Journal
|
-- readJournalWithOpts :: CliOpts -> String -> IO Journal
|
||||||
-- readJournalWithOpts opts s = readJournal Nothing Nothing Nothing s >>= either error' return
|
-- readJournalWithOpts opts s = readJournal Nothing Nothing Nothing s >>= either error' return
|
||||||
|
|
||||||
-- | Re-read a journal from its data file, or return an error string.
|
-- | Re-read the journal file(s) specified by options, or return an error string.
|
||||||
journalReload :: Journal -> IO (Either String Journal)
|
-- Options are honoured and the provided date is used as the current date.
|
||||||
journalReload j = readJournalFile Nothing Nothing True $ journalFilePath j
|
journalReload :: CliOpts -> IO (Either String Journal)
|
||||||
|
journalReload opts = do
|
||||||
|
rulespath <- rulesFilePathFromOpts opts
|
||||||
|
journalpaths <- journalFilePathFromOpts opts
|
||||||
|
readJournalFiles Nothing rulespath (not $ ignore_assertions_ opts) journalpaths
|
||||||
|
|
||||||
-- | Re-read a journal from its data file mostly, only if the file has
|
-- | Re-read the journal file(s) specified by options, but only if any
|
||||||
-- changed since last read (or if there is no file, ie data read from
|
-- of them has changed since last read (or if there is no file, ie
|
||||||
-- stdin). The provided options and current date are used to filter
|
-- data read from stdin). The provided options and current date are
|
||||||
-- the re-read journal; this is intended to reapply the same filter as
|
-- used to filter the re-read journal; this is intended to reapply the
|
||||||
-- at program startup (though, the current date may not be what it was
|
-- same filter as at program startup (though, the current date may not
|
||||||
-- then, so results may differ). Returns a journal or error message,
|
-- be what it was then, so results may differ). Returns a journal or
|
||||||
-- and a flag indicating whether it was re-read or not.
|
-- error message, and a flag indicating whether it was re-read or not.
|
||||||
journalReloadIfChanged :: CliOpts -> Day -> Journal -> IO (Either String Journal, Bool)
|
journalReloadIfChanged :: CliOpts -> Day -> Journal -> IO (Either String Journal, Bool)
|
||||||
journalReloadIfChanged opts d j = do
|
journalReloadIfChanged opts d j = do
|
||||||
let maybeChangedFilename f = do newer <- journalSpecifiedFileIsNewer j f
|
let maybeChangedFilename f = do newer <- journalSpecifiedFileIsNewer j f
|
||||||
@ -102,7 +106,7 @@ journalReloadIfChanged opts d j = do
|
|||||||
if not $ null changedfiles
|
if not $ null changedfiles
|
||||||
then do
|
then do
|
||||||
whenLoud $ printf "%s has changed, reloading\n" (head changedfiles)
|
whenLoud $ printf "%s has changed, reloading\n" (head changedfiles)
|
||||||
ej <- journalReload j
|
ej <- journalReload opts
|
||||||
let initq = queryFromOpts d $ reportopts_ opts
|
let initq = queryFromOpts d $ reportopts_ opts
|
||||||
ej' = filterJournalTransactions initq <$> ej
|
ej' = filterJournalTransactions initq <$> ej
|
||||||
return (ej', True)
|
return (ej', True)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user