From 4e4bfd27d0cf5e042bc22a80076b6fa9b0e71d6d Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 23 Jun 2022 17:43:21 +0200 Subject: [PATCH] SaveFile: the chmod is optional, fixes #6786 some filesystems do not support chmod, just ignore if it is failing. --- src/borg/platform/base.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/borg/platform/base.py b/src/borg/platform/base.py index 3cfd82974..d6f2aae8f 100644 --- a/src/borg/platform/base.py +++ b/src/borg/platform/base.py @@ -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