summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/atomic_helper.py4
-rw-r--r--cloudinit/ssh_util.py2
-rw-r--r--cloudinit/util.py6
3 files changed, 7 insertions, 5 deletions
diff --git a/cloudinit/atomic_helper.py b/cloudinit/atomic_helper.py
index 1f61faa2..485ff92f 100644
--- a/cloudinit/atomic_helper.py
+++ b/cloudinit/atomic_helper.py
@@ -11,10 +11,10 @@ LOG = logging.getLogger(__name__)
def write_file(filename, content, mode=_DEF_PERMS,
- omode="wb", copy_mode=False):
+ omode="wb", preserve_mode=False):
# open filename in mode 'omode', write content, set permissions to 'mode'
- if copy_mode:
+ if preserve_mode:
try:
file_stat = os.stat(filename)
mode = stat.S_IMODE(file_stat.st_mode)
diff --git a/cloudinit/ssh_util.py b/cloudinit/ssh_util.py
index 918c4aec..72e4e65e 100644
--- a/cloudinit/ssh_util.py
+++ b/cloudinit/ssh_util.py
@@ -346,7 +346,7 @@ def update_ssh_config(updates, fname=DEF_SSHD_CFG):
util.write_file(
fname, "\n".join(
[str(line) for line in lines]
- ) + "\n", copy_mode=True)
+ ) + "\n", preserve_mode=True)
return len(changed) != 0
diff --git a/cloudinit/util.py b/cloudinit/util.py
index ab2df59e..23d24c4c 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1800,7 +1800,7 @@ def chmod(path, mode):
os.chmod(path, real_mode)
-def write_file(filename, content, mode=0o644, omode="wb", copy_mode=False):
+def write_file(filename, content, mode=0o644, omode="wb", preserve_mode=False):
"""
Writes a file with the given content and sets the file mode as specified.
Restores the SELinux context if possible.
@@ -1809,9 +1809,11 @@ def write_file(filename, content, mode=0o644, omode="wb", copy_mode=False):
@param content: The content to write to the file.
@param mode: The filesystem mode to set on the file.
@param omode: The open mode used when opening the file (w, wb, a, etc.)
+ @param preserve_mode: If True and `filename` exists, preserve `filename`s
+ current mode instead of applying `mode`.
"""
- if copy_mode:
+ if preserve_mode:
try:
file_stat = os.stat(filename)
mode = stat.S_IMODE(file_stat.st_mode)