builder.py: create temp log file in the same directory as the final one.

We're going to rename() it from the temp name to the final name, which
doesn't work across filesystems, so the safest option is to keep it in
the same directory.

Reported-by: spacefrogg@meterriblecrew.net
This commit is contained in:
Avery Pennarun 2019-03-12 00:03:34 -04:00
commit 7238b370e4

View file

@ -240,9 +240,15 @@ class _BuildJob(object):
# reading a previous instance created during this session. It # reading a previous instance created during this session. It
# should always see either the old or new instance. # should always see either the old or new instance.
if env.v.LOG: if env.v.LOG:
lfd, lfname = tempfile.mkstemp(prefix='redo.', suffix='.log.tmp') lfend = state.logname(self.sf.id)
# Make sure the temp file is in the same directory as lfend,
# so we can be sure of our ability to rename it atomically later.
lfd, lfname = tempfile.mkstemp(
prefix='redo.',
suffix='.log.tmp',
dir=os.path.dirname(lfend))
os.fdopen(lfd, 'w') os.fdopen(lfd, 'w')
os.rename(lfname, state.logname(self.sf.id)) os.rename(lfname, lfend)
dof = state.File(name=os.path.join(dodir, dofile)) dof = state.File(name=os.path.join(dodir, dofile))
dof.set_static() dof.set_static()
dof.save() dof.save()