From 2c3f1b672e4ff722606b10a4dac73a235dd6e6a6 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 27 Sep 2015 08:17:12 -1000 Subject: [PATCH] web: disallow -f- which doesn't work (fixes #202) hledger-web -f- gives [Error#yesod-core] : hGetContents: illegal operation (handle is closed) and I can't see why. Just disallow it. --- hledger-web/Hledger/Web/Main.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hledger-web/Hledger/Web/Main.hs b/hledger-web/Hledger/Web/Main.hs index ba94535c0..6377690d8 100644 --- a/hledger-web/Hledger/Web/Main.hs +++ b/hledger-web/Hledger/Web/Main.hs @@ -52,9 +52,15 @@ runWith opts withJournalDo' :: WebOpts -> (WebOpts -> Journal -> IO ()) -> IO () withJournalDo' opts cmd = do - -- XXX head should be safe for now - (head `fmap` journalFilePathFromOpts (cliopts_ opts)) >>= readJournalFile Nothing Nothing True >>= - either error' (cmd opts . journalApplyAliases (aliasesFromOpts $ cliopts_ opts)) + f <- head `fmap` journalFilePathFromOpts (cliopts_ opts) -- XXX head should be safe for now + + -- https://github.com/simonmichael/hledger/issues/202 + -- -f- gives [Error#yesod-core] : hGetContents: illegal operation (handle is closed) for some reason + -- Also we may be writing to this file. Just disallow it. + when (f == "-") $ error' "hledger-web doesn't support --f -, please specify a file path" + + readJournalFile Nothing Nothing True f >>= + either error' (cmd opts . journalApplyAliases (aliasesFromOpts $ cliopts_ opts)) -- | The web command. web :: WebOpts -> Journal -> IO ()