summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorDaniel Watkins <oddbloke@ubuntu.com>2020-06-17 12:59:23 -0400
committerGitHub <noreply@github.com>2020-06-17 10:59:23 -0600
commit3d13a9dd469f354d0ddc1e36be37d743b5a57c73 (patch)
treeeb6fbcf7f66c5c67e7703858f93369e8934b9c34 /cloudinit/util.py
parente01e3ed5444c8093de47229e20abec440530d549 (diff)
downloadvyos-cloud-init-3d13a9dd469f354d0ddc1e36be37d743b5a57c73.tar.gz
vyos-cloud-init-3d13a9dd469f354d0ddc1e36be37d743b5a57c73.zip
util: rename write_file's copy_mode parameter to preserve_mode (#439)
When updating the docstring to include it, I realised that the current name is somewhat misleading; this makes it a little easier to understand, I think.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py6
1 files changed, 4 insertions, 2 deletions
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)