From d9833f227fb016563c389edb9fe5857feb6d5405 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 12 Aug 2015 14:25:54 -0400 Subject: [PATCH] Make sure cached data from file loads isn't impacted by modifications Fixes #11893 --- lib/ansible/parsing/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/ansible/parsing/__init__.py b/lib/ansible/parsing/__init__.py index 749a386572c..bf0d0aff5e6 100644 --- a/lib/ansible/parsing/__init__.py +++ b/lib/ansible/parsing/__init__.py @@ -19,6 +19,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import copy import json import os @@ -100,16 +101,17 @@ class DataLoader(): # if the file has already been read in and cached, we'll # return those results to avoid more file/vault operations if file_name in self._FILE_CACHE: - return self._FILE_CACHE[file_name] - - # read the file contents and load the data structure from them - (file_data, show_content) = self._get_file_contents(file_name) - parsed_data = self.load(data=file_data, file_name=file_name, show_content=show_content) + parsed_data = self._FILE_CACHE[file_name] + else: + # read the file contents and load the data structure from them + (file_data, show_content) = self._get_file_contents(file_name) + parsed_data = self.load(data=file_data, file_name=file_name, show_content=show_content) - # cache the file contents for next time - self._FILE_CACHE[file_name] = parsed_data + # cache the file contents for next time + self._FILE_CACHE[file_name] = parsed_data - return parsed_data + # return a deep copy here, so the cache is not affected + return copy.deepcopy(parsed_data) def path_exists(self, path): path = self.path_dwim(path)