ui: fix a recent reload breakage (fixes #346)
Commit 0a90ef4 a few weeks ago caused hledger-ui to show wrong balances
after reloading with the g key, if the journal had changed and you had
specified a query on the command line.
Now, journalReloadIfChanged reloads the full journal without filtering,
like journalReload and withJournalDo.
This commit is contained in:
parent
550e99acd3
commit
72bdce39b6
@ -271,9 +271,12 @@ getViewData = do
|
|||||||
-- XXX put this inside atomicModifyIORef' for thread safety
|
-- XXX put this inside atomicModifyIORef' for thread safety
|
||||||
j <- liftIO $ readIORef $ appJournal app
|
j <- liftIO $ readIORef $ appJournal app
|
||||||
(ej, changed) <- liftIO $ journalReloadIfChanged opts d j
|
(ej, changed) <- liftIO $ journalReloadIfChanged opts d j
|
||||||
|
-- re-apply any initial filter specified at startup
|
||||||
|
let initq = queryFromOpts d $ reportopts_ opts
|
||||||
|
ej' = filterJournalTransactions initq <$> ej
|
||||||
if not changed
|
if not changed
|
||||||
then return (j,Nothing)
|
then return (j,Nothing)
|
||||||
else case ej of
|
else case ej' of
|
||||||
Right j' -> do liftIO $ writeIORef (appJournal app) j'
|
Right j' -> do liftIO $ writeIORef (appJournal app) j'
|
||||||
return (j',Nothing)
|
return (j',Nothing)
|
||||||
Left e -> do setMessage $ "error while reading" {- ++ ": " ++ e-}
|
Left e -> do setMessage $ "error while reading" {- ++ ": " ++ e-}
|
||||||
|
|||||||
@ -57,7 +57,6 @@ import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds)
|
|||||||
import Hledger.Cli.CliOptions
|
import Hledger.Cli.CliOptions
|
||||||
import Hledger.Data
|
import Hledger.Data
|
||||||
import Hledger.Read
|
import Hledger.Read
|
||||||
import Hledger.Reports (queryFromOpts)
|
|
||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
|
|
||||||
|
|
||||||
@ -101,22 +100,21 @@ writeOutput opts s = do
|
|||||||
-- readJournalWithOpts opts s = readJournal Nothing Nothing Nothing s >>= either error' return
|
-- readJournalWithOpts opts s = readJournal Nothing Nothing Nothing s >>= either error' return
|
||||||
|
|
||||||
-- | Re-read the journal file(s) specified by options, or return an error string.
|
-- | Re-read the journal file(s) specified by options, or return an error string.
|
||||||
-- Options are honoured and the provided date is used as the current date.
|
-- Reads the full journal, without filtering.
|
||||||
journalReload :: CliOpts -> IO (Either String Journal)
|
journalReload :: CliOpts -> IO (Either String Journal)
|
||||||
journalReload opts = do
|
journalReload opts = do
|
||||||
rulespath <- rulesFilePathFromOpts opts
|
rulespath <- rulesFilePathFromOpts opts
|
||||||
journalpaths <- journalFilePathFromOpts opts
|
journalpaths <- journalFilePathFromOpts opts
|
||||||
readJournalFiles Nothing rulespath (not $ ignore_assertions_ opts) journalpaths
|
readJournalFiles Nothing rulespath (not $ ignore_assertions_ opts) journalpaths
|
||||||
|
|
||||||
-- | Re-read the journal file(s) specified by options, but only if any
|
-- | Re-read the option-specified journal file(s), but only if any of
|
||||||
-- of them has changed since last read (or if there is no file, ie
|
-- them has changed since last read. (If the file is standard input,
|
||||||
-- data read from stdin). The provided options and current date are
|
-- this will either do nothing or give an error, not tested yet).
|
||||||
-- used to filter the re-read journal; this is intended to reapply the
|
-- Returns a journal or error message, and a flag indicating whether
|
||||||
-- same filter as at program startup (though, the current date may not
|
-- it was re-read or not. Like withJournalDo and journalReload, reads
|
||||||
-- be what it was then, so results may differ). Returns a journal or
|
-- the full journal, without filtering.
|
||||||
-- 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
|
||||||
return $ if newer then Just f else Nothing
|
return $ if newer then Just f else Nothing
|
||||||
changedfiles <- catMaybes `fmap` mapM maybeChangedFilename (journalFilePaths j)
|
changedfiles <- catMaybes `fmap` mapM maybeChangedFilename (journalFilePaths j)
|
||||||
@ -124,9 +122,7 @@ journalReloadIfChanged opts d j = do
|
|||||||
then do
|
then do
|
||||||
whenLoud $ printf "%s has changed, reloading\n" (head changedfiles)
|
whenLoud $ printf "%s has changed, reloading\n" (head changedfiles)
|
||||||
ej <- journalReload opts
|
ej <- journalReload opts
|
||||||
let initq = queryFromOpts d $ reportopts_ opts
|
return (ej, True)
|
||||||
ej' = filterJournalTransactions initq <$> ej
|
|
||||||
return (ej', True)
|
|
||||||
else
|
else
|
||||||
return (Right j, False)
|
return (Right j, False)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user