From 5916180c5ecb2ef74c1c993dcd32f95cb4581172 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 18 Mar 2016 19:55:53 -0400 Subject: add atomic_write_file and use it from atomic_write_json atomic_write_file just does less and easily utilized for the same purpose that atomic_write_json served. --- bin/cloud-init | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/cloud-init b/bin/cloud-init index 7f665e7e..42166580 100755 --- a/bin/cloud-init +++ b/bin/cloud-init @@ -435,20 +435,24 @@ def main_single(name, args): return 0 -def atomic_write_json(path, data): +def atomic_write_file(path, content, mode='w'): tf = None try: tf = tempfile.NamedTemporaryFile(dir=os.path.dirname(path), - delete=False) - tf.write(util.encode_text(json.dumps(data, indent=1) + "\n")) + delete=False, mode=mode) + tf.write(content)u tf.close() os.rename(tf.name, path) except Exception as e: if tf is not None: - util.del_file(tf.name) + os.unlink(tf.name) raise e +def atomic_write_json(path, data): + return atomic_write_file(path, json.dumps(data, indent=1) + "\n") + + def status_wrapper(name, args, data_d=None, link_d=None): if data_d is None: data_d = os.path.normpath("/var/lib/cloud/data") -- cgit v1.2.3