From 0a5832e8d70cc0107a9bacd71e717bafa8748357 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 6 Jun 2023 12:25:34 -0400 Subject: [PATCH] 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) --- src/cephadm/cephadm.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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']) -- 2.39.5