Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep config file permissions #161

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
11 changes: 11 additions & 0 deletions mautrix/util/config/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from __future__ import annotations

from abc import ABC
from stat import S_IMODE
import logging
import os
import pkgutil
Expand Down Expand Up @@ -55,6 +56,16 @@ def save(self) -> None:
except OSError as e:
log.warning(f"Failed to create tempfile to write updated config to disk: {e}")
return
try:
mode = S_IMODE(os.stat(self.path).st_mode)
os.chmod(tf.name, mode)
except FileNotFoundError:
pass
except OSError as e:
log.warning(f"Failed to copy permissions to tempfile: {e}")
tf.file.close()
os.remove(tf.name)
return
try:
yaml.dump(self._data, tf)
except OSError as e:
Expand Down