@@ -67,13 +67,13 @@ def _cleanup_temp_files():
6767 _temp_files = {}
6868
6969
70- def _create_temp_file_with_content (content , temp_file_path = None ):
70+ def _create_temp_file_with_content (content , temp_file_path = None , force_recreate = False ):
7171 if len (_temp_files ) == 0 :
7272 atexit .register (_cleanup_temp_files )
7373 # Because we may change context several times, try to remember files we
7474 # created and reuse them at a small memory cost.
7575 content_key = str (content )
76- if content_key in _temp_files :
76+ if not force_recreate and content_key in _temp_files :
7777 return _temp_files [content_key ]
7878 if temp_file_path and not os .path .isdir (temp_file_path ):
7979 os .makedirs (name = temp_file_path )
@@ -122,16 +122,10 @@ def as_file(self):
122122 decoded obj[%data_key_name] content otherwise obj[%file_key_name]."""
123123 use_data_if_no_file = not self ._file and self ._data
124124 if use_data_if_no_file :
125- if self ._base64_file_content :
126- if isinstance (self ._data , str ):
127- content = self ._data .encode ()
128- else :
129- content = self ._data
130- self ._file = _create_temp_file_with_content (
131- base64 .standard_b64decode (content ), self ._temp_file_path )
132- else :
133- self ._file = _create_temp_file_with_content (
134- self ._data , self ._temp_file_path )
125+ self ._write_file ()
126+
127+ if self ._file and not os .path .isfile (self ._file ):
128+ self ._write_file (force_rewrite = True )
135129 if self ._file and not os .path .isfile (self ._file ):
136130 raise ConfigException ("File does not exist: %s" % self ._file )
137131 return self ._file
@@ -149,6 +143,18 @@ def as_data(self):
149143 self ._data = f .read ()
150144 return self ._data
151145
146+ def _write_file (self , force_rewrite = False ):
147+ if self ._base64_file_content :
148+ if isinstance (self ._data , str ):
149+ content = self ._data .encode ()
150+ else :
151+ content = self ._data
152+ self ._file = _create_temp_file_with_content (
153+ base64 .standard_b64decode (content ), self ._temp_file_path , force_recreate = force_rewrite )
154+ else :
155+ self ._file = _create_temp_file_with_content (
156+ self ._data , self ._temp_file_path , force_recreate = force_rewrite )
157+
152158
153159class CommandTokenSource (object ):
154160 def __init__ (self , cmd , args , tokenKey , expiryKey ):
0 commit comments