mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-20 21:27:32 +00:00
SaveFile: respect umask for final file mode, fixes #6400
This commit is contained in:
parent
a82673e708
commit
0f9d88bf2e
1 changed files with 10 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
|||
import tempfile
|
||||
import uuid
|
||||
|
||||
from borg.constants import UMASK_DEFAULT
|
||||
from borg.helpers import safe_unlink
|
||||
from borg.platformflags import is_win32
|
||||
|
||||
|
@ -237,6 +238,15 @@ def __exit__(self, exc_type, exc_val, exc_tb):
|
|||
if exc_type is not None:
|
||||
safe_unlink(self.tmp_fname) # with-body has failed, clean up tmp file
|
||||
return # continue processing the exception normally
|
||||
|
||||
# tempfile.mkstemp always uses owner-only file permissions for the temp file,
|
||||
# but as we'll rename it to the non-temp permanent file now, we need to respect
|
||||
# the umask and change the file mode to what a normally created file would have.
|
||||
# thanks to the crappy os.umask api, we can't query the umask without setting it. :-(
|
||||
umask = os.umask(UMASK_DEFAULT)
|
||||
os.umask(umask)
|
||||
os.chmod(self.tmp_fname, mode=0o666 & ~ umask)
|
||||
|
||||
try:
|
||||
os.replace(self.tmp_fname, self.path) # POSIX: atomic rename
|
||||
except OSError:
|
||||
|
|
Loading…
Reference in a new issue