1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-24 08:45:13 +00:00

SaveFile: the chmod is optional, fixes #6786

some filesystems do not support chmod, just ignore if it is failing.
This commit is contained in:
Thomas Waldmann 2022-06-23 17:43:21 +02:00
parent 1576859ec0
commit 4e4bfd27d0

View file

@ -239,13 +239,18 @@ def __exit__(self, exc_type, exc_val, exc_tb):
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:
# 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)
except OSError:
# chmod might fail if the fs does not support it.
# this is not harmful, the file will still have permissions for the owner.
pass
try:
os.replace(self.tmp_fname, self.path) # POSIX: atomic rename