]> arthur.barton.de Git - bup.git/commit
atomically_replaced_file: respect umask/sgid/etc. via tmpdir
authorRob Browning <rlb@defaultvalue.org>
Fri, 24 Jun 2022 16:41:36 +0000 (11:41 -0500)
committerRob Browning <rlb@defaultvalue.org>
Fri, 1 Jul 2022 18:19:27 +0000 (13:19 -0500)
commit80f7aa7c3b3935f8f344e1870400ae9512b96a3a
tree3a78c7994d858ae0b8c2731416a2c01482ae7542
parentde7cf6afa1bc8cd97f77614f4d212dd25f6d800f
atomically_replaced_file: respect umask/sgid/etc. via tmpdir

Don't create the tempfile via mkstemp because it always creates files
with restricted permissions, which is not what we want for a new
packfile (for example).  The replacement files should respect the
environment umask, directory sgid bits, etc.

Instead, create a normally open()ed file in a mkdtemp directory in the
same directory as the target path.  Don't use TemporaryDirectory
because it's a @contextmanager (see below).

Add a missing '+' to the midx open mode.  Without it mmap_readwrite's mmap
will fail with EACCES.  This wasn't an issue with the previous
implementation because mkstemp doesn't accept a full mode string.

Also drop @contextmanager.  Because it involves a generator,
@contextmanager creates managers that are incompatible with
ExitStack.pop_all() because they close during that call -- exactly
what pop_all() is intended to avoid.

cf. https://github.com/python/cpython/issues/88458

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/cmd/midx.py
lib/bup/helpers.py