From ee9c84aadb35fdee6374bac16444c4e799c194e1 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 24 Feb 2010 15:41:07 -0500 Subject: ensure that cache dir is present if not created, and tighten permissions on object cache stored there. --- cloudinit/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'cloudinit/__init__.py') diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 65ca6d7f..8d6ec59e 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -103,9 +103,16 @@ class CloudInit: return False 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 -- cgit v1.2.3