summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2010-02-24 15:41:07 -0500
committerScott Moser <smoser@ubuntu.com>2010-02-24 15:41:07 -0500
commitee9c84aadb35fdee6374bac16444c4e799c194e1 (patch)
tree656e770845aeaaa9a25923db416a79d536d5001f
parent112cb9de6b55f0b1a24a9ae9e292f2f98c77f737 (diff)
downloadvyos-cloud-init-ee9c84aadb35fdee6374bac16444c4e799c194e1.tar.gz
vyos-cloud-init-ee9c84aadb35fdee6374bac16444c4e799c194e1.zip
ensure that cache dir is present if not created, and tighten permissions
on object cache stored there.
-rw-r--r--cloudinit/__init__.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py
index 65ca6d7f..8d6ec59e 100644
--- a/cloudinit/__init__.py
+++ b/cloudinit/__init__.py
@@ -104,8 +104,15 @@ class CloudInit:
def write_to_cache(self):
try:
+ os.makedirs(os.path.dirname(data_source_cache))
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ return False
+
+ try:
f=open(data_source_cache, "wb")
data = cPickle.dump(self.datasource,f)
+ os.chmod(data_source_cache,0400)
return True
except:
return False