From 3cfdf654f65882ae3d618b6e7d17d03bf08f9fcb Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 31 Aug 2010 14:35:36 -0400 Subject: append to apt_sources filenames rather than truncating. Previously, apt_sources: - source: source1 - source: source2 resulted in source1 being written to /etc/apt/sources.list.d/cloud_config_sources.list , and then that being overwritten by source2. This definitely is not expected. Instead, in all cases now, (including 'filename:' cases), just append. LP: #627597 --- cloudinit/CloudConfig/cc_apt_update_upgrade.py | 2 +- cloudinit/util.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/CloudConfig/cc_apt_update_upgrade.py b/cloudinit/CloudConfig/cc_apt_update_upgrade.py index e1226c85..396c5e09 100644 --- a/cloudinit/CloudConfig/cc_apt_update_upgrade.py +++ b/cloudinit/CloudConfig/cc_apt_update_upgrade.py @@ -142,7 +142,7 @@ def add_sources(srclist): except: elst.append([source, "failed add key"]) - try: util.write_file(ent['filename'], source + "\n") + try: util.write_file(ent['filename'], source + "\n", omode="ab") except: elst.append([source, "failed write to file %s" % ent['filename']]) diff --git a/cloudinit/util.py b/cloudinit/util.py index be84bfdc..c1b4fd2d 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -76,15 +76,16 @@ def mergedict(src,cand): src[k] = mergedict(src[k],v) return src -def write_file(file,content,mode=0644): +def write_file(file,content,mode=0644,omode="wb"): try: os.makedirs(os.path.dirname(file)) except OSError as e: if e.errno != errno.EEXIST: raise e - f=open(file,"wb") - os.chmod(file,mode) + f=open(file,omode) + if mode != None: + os.chmod(file,mode) f.write(content) f.close() -- cgit v1.2.3