aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-06-08 14:42:44 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-06-08 14:44:17 -0400
commite74cfbb808f386e6909632300bab653f7033601d (patch)
treebb42521ac6836b4cd7b8d68a6139727b405ccdd3
parent8d14a7a089acad173917bb03d204b69c15450391 (diff)
downloadb4-e74cfbb808f386e6909632300bab653f7033601d.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.py32
1 files changed, 15 insertions, 17 deletions
diff --git a/b4/mbox.py b/b4/mbox.py
index ab8dcea..d40c3df 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -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)