]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-12553] remote write_file - remove file first if it exists 335/head
authorTravis Rhoden <trhoden@redhat.com>
Tue, 4 Aug 2015 20:07:47 +0000 (13:07 -0700)
committerTravis Rhoden <trhoden@redhat.com>
Tue, 4 Aug 2015 20:07:47 +0000 (13:07 -0700)
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 <trhoden@redhat.com>
ceph_deploy/hosts/remotes.py

index b17fcb24499e58711bab85148999adce02334639..b857cd3ead4610586a9f98aaf6e03b5420819733 100644 (file)
@@ -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)