mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
5f617c601b
commit
0aa018337a
1 changed files with 13 additions and 16 deletions
17
lib/ansible/plugins/cache/jsonfile.py
vendored
17
lib/ansible/plugins/cache/jsonfile.py
vendored
|
@ -53,19 +53,15 @@ class CacheModule(BaseCacheModule):
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
|
|
||||||
|
if self.has_expired(key) or key == "":
|
||||||
|
raise KeyError
|
||||||
|
|
||||||
if key in self._cache:
|
if key in self._cache:
|
||||||
return self._cache.get(key)
|
return self._cache.get(key)
|
||||||
|
|
||||||
if self.has_expired(key):
|
|
||||||
raise KeyError
|
|
||||||
|
|
||||||
cachefile = "%s/%s" % (self._cache_dir, key)
|
cachefile = "%s/%s" % (self._cache_dir, key)
|
||||||
try:
|
try:
|
||||||
f = codecs.open(cachefile, 'r', encoding='utf-8')
|
with codecs.open(cachefile, 'r', encoding='utf-8') as f:
|
||||||
except (OSError,IOError) as e:
|
|
||||||
self._display.warning("error while trying to read %s : %s" % (cachefile, to_bytes(e)))
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
value = json.load(f)
|
value = json.load(f)
|
||||||
self._cache[key] = value
|
self._cache[key] = value
|
||||||
|
@ -74,8 +70,9 @@ class CacheModule(BaseCacheModule):
|
||||||
self._display.warning("error while trying to read %s : %s. Most likely a corrupt file, so erasing and failing." % (cachefile, to_bytes(e)))
|
self._display.warning("error while trying to read %s : %s. Most likely a corrupt file, so erasing and failing." % (cachefile, to_bytes(e)))
|
||||||
self.delete(key)
|
self.delete(key)
|
||||||
raise AnsibleError("The JSON cache file %s was corrupt, or did not otherwise contain valid JSON data. It has been removed, so you can re-run your command now." % cachefile)
|
raise AnsibleError("The JSON cache file %s was corrupt, or did not otherwise contain valid JSON data. It has been removed, so you can re-run your command now." % cachefile)
|
||||||
finally:
|
except (OSError,IOError) as e:
|
||||||
f.close()
|
self._display.warning("error while trying to read %s : %s" % (cachefile, to_bytes(e)))
|
||||||
|
raise KeyError
|
||||||
|
|
||||||
def set(self, key, value):
|
def set(self, key, value):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue