From 56880827e096232a574a34343f1eec1086658aed Mon Sep 17 00:00:00 2001 From: Travis Rhoden Date: Tue, 4 Aug 2015 13:07:47 -0700 Subject: [PATCH] [RM-12553] remote write_file - remove file first if it exists This way a new file mode can be applied if it has changed. Since we are always writing the whole file (mode 'w') rather than appending, we aren't losing anything by doing this. Signed-off-by: Travis Rhoden --- ceph_deploy/hosts/remotes.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ceph_deploy/hosts/remotes.py b/ceph_deploy/hosts/remotes.py index b17fcb2..b857cd3 100644 --- a/ceph_deploy/hosts/remotes.py +++ b/ceph_deploy/hosts/remotes.py @@ -215,6 +215,9 @@ def write_file(path, content, mode=0644, directory=None, uid=-1, gid=-1): if path.startswith("/"): path = path[1:] path = os.path.join(directory, path) + if os.path.exists(path): + # Delete file in case we are changing its mode + os.unlink(path) with os.fdopen(os.open(path, os.O_WRONLY | os.O_CREAT, mode), 'w') as f: f.write(content) os.chown(path, uid, gid) -- 2.47.3