summaryrefslogtreecommitdiff
path: root/Command/FromKey.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-25 11:46:07 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-25 11:51:06 -0400
commit12243d2279cae65ed163bdec1edb268817514265 (patch)
tree9e8dfecb67c8e070a2e9d929d4ee9bf142bbc369 /Command/FromKey.hs
parent566a5f4881ef036d748ebc55140358087aaae63c (diff)
Flush json output, avoiding a buffering problem that could result in doubled output.
The bug was that with --json, output lines were sometimes doubled. For example, git annex init --json would output two lines, despite only running one thing. Adding to the weirdness, this only occurred when the output was redirected to a pipe or a file. Strace showed two processes outputting the same buffered output. The second process was this writer process (only needed to work around bug #624389): _ <- forkProcess $ do hPutStr toh $ unlines paths hClose toh exitSuccess The doubled output occurs when this process exits, and ghc flushes the inherited stdout buffer. Why only when piping? I don't know, but ghc may be behaving differently when stdout is not a terminal. While this is quite possibly a ghc bug, there is a nice fix in git-annex. Explicitly flushing after each chunk of json is output works around the problem, and as a side effect, json is streamed rather than being output all at the end when performing an expensive operaition. However, note that this means all uses of putStr in git-annex must be explicitly flushed. The others were, already.
Diffstat (limited to 'Command/FromKey.hs')
0 files changed, 0 insertions, 0 deletions