diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-06-08 14:42:44 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-06-08 14:42:44 -0400 |
commit | ca902b59c3d135ddbd64d9fba9fa3ef995555f0c (patch) | |
tree | 7bb7bc07bddd5675a45ec86faf722839f6acd003 | |
parent | 1f946b903ee0ba42df9107dc484dcd5ff27b83d3 (diff) | |
download | b4-ca902b59c3d135ddbd64d9fba9fa3ef995555f0c.tar.gz |
Fix mbox naming inconsistencies
Fix mbox file naming problems introduced by adding "-o -".
Reported-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/mbox.py | 32 |
1 files changed, 15 insertions, 17 deletions
@@ -472,26 +472,14 @@ def main(cmdargs): # Force nocache mode cmdargs.nocache = True + savefile = mkstemp('b4-mbox')[1] + if not cmdargs.localmbox: msgid = b4.get_msgid(cmdargs) - wantname = cmdargs.wantname - outdir = cmdargs.outdir - if outdir == '-': - savefile = mkstemp('b4-mbox')[1] - elif wantname: - savefile = os.path.join(outdir, wantname) - else: - # Save it into msgid.mbox - savefile = '%s.t.mbx' % msgid - savefile = os.path.join(outdir, savefile) - mboxfile = b4.get_pi_thread_by_msgid(msgid, savefile, useproject=cmdargs.useproject, nocache=cmdargs.nocache) - if mboxfile is None: + threadmbox = b4.get_pi_thread_by_msgid(msgid, savefile, useproject=cmdargs.useproject, nocache=cmdargs.nocache) + if threadmbox is None: return - - # Move it into -thread - threadmbox = '%s-thread' % mboxfile - os.rename(mboxfile, threadmbox) else: if os.path.exists(cmdargs.localmbox): threadmbox = cmdargs.localmbox @@ -508,7 +496,6 @@ def main(cmdargs): os.unlink(threadmbox) else: mbx = mailbox.mbox(threadmbox) - logger.critical('Saved %s', threadmbox) logger.critical('%s messages in the thread', len(mbx)) mbx.close() if cmdargs.outdir == '-': @@ -516,3 +503,14 @@ def main(cmdargs): with open(threadmbox, 'r') as fh: shutil.copyfileobj(fh, sys.stdout) os.unlink(threadmbox) + return + + if cmdargs.wantname: + savefile = os.path.join(cmdargs.outdir, cmdargs.wantname) + else: + savefile = os.path.join(cmdargs.outdir, '%s.mbx' % msgid) + + shutil.copy(threadmbox, savefile) + logger.info('Saved %s', savefile) + if not cmdargs.localmbox: + os.unlink(threadmbox) |