From: Travis Rhoden Date: Tue, 4 Aug 2015 20:07:47 +0000 (-0700) Subject: [RM-12553] remote write_file - remove file first if it exists X-Git-Tag: v1.5.27~4^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=56880827e096232a574a34343f1eec1086658aed;p=ceph-deploy.git [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 --- 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)