Python 3.x tempfile requires unicode

Explicitly encode the output of yaml dump, and allow tempfile to handle
the unicode output as it works correctly for python 2.7 and 3.x+

Change-Id: I919b2565a7f3857586ee6cc09b787160472e9deb
This commit is contained in:
Darragh Bailey 2016-05-25 19:13:45 +01:00
parent 008082568c
commit 7d13236760

View File

@ -105,7 +105,7 @@ class CacheStorage(object):
# issues around corruption such the process be killed
tfile = self._tempfile.NamedTemporaryFile(dir=self.get_cache_dir(),
delete=False)
self._yaml.dump(self.data, utils.wrap_stream(tfile))
tfile.write(self._yaml.dump(self.data).encode('utf-8'))
# force contents to be synced on disk before overwriting cachefile
tfile.flush()
self._os.fsync(tfile.fileno())