From: John Mulligan Date: Tue, 6 Jun 2023 16:25:34 +0000 (-0400) Subject: cephadm: convert _write_custom_conf_files to use write_new X-Git-Tag: v18.2.1~326^2~84 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0a5832e8d70cc0107a9bacd71e717bafa8748357;p=ceph.git cephadm: convert _write_custom_conf_files to use write_new We double checked the meaning of "w+" and it will open the file read-write. Since the file is never read there's no real reason to keep it that way so its OK to convert to `write_new`. Signed-off-by: John Mulligan (cherry picked from commit 642985c6894f8f62a313cd70c915d066f9c53d6e) --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 8202304296f3e..0ee95a2fcee7b 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -2964,9 +2964,7 @@ def _write_custom_conf_files(ctx: CephadmContext, daemon_type: str, daemon_id: s for ccf in config_json['custom_config_files']: if all(k in ccf for k in mandatory_keys): file_path = os.path.join(custom_config_dir, os.path.basename(ccf['mount_path'])) - with open(file_path, 'w+', encoding='utf-8') as f: - os.fchown(f.fileno(), uid, gid) - os.fchmod(f.fileno(), 0o600) + with write_new(file_path, owner=(uid, gid), perms=0o600, encoding='utf-8') as f: f.write(ccf['content'])