@@ -60,13 +60,13 @@ def _cleanup_temp_files():
60
60
_temp_files = {}
61
61
62
62
63
- def _create_temp_file_with_content (content , temp_file_path = None ):
63
+ def _create_temp_file_with_content (content , temp_file_path = None , force_recreate = False ):
64
64
if len (_temp_files ) == 0 :
65
65
atexit .register (_cleanup_temp_files )
66
66
# Because we may change context several times, try to remember files we
67
67
# created and reuse them at a small memory cost.
68
68
content_key = str (content )
69
- if content_key in _temp_files :
69
+ if not force_recreate and content_key in _temp_files :
70
70
return _temp_files [content_key ]
71
71
if temp_file_path and not os .path .isdir (temp_file_path ):
72
72
os .makedirs (name = temp_file_path )
@@ -115,16 +115,10 @@ def as_file(self):
115
115
decoded obj[%data_key_name] content otherwise obj[%file_key_name]."""
116
116
use_data_if_no_file = not self ._file and self ._data
117
117
if use_data_if_no_file :
118
- if self ._base64_file_content :
119
- if isinstance (self ._data , str ):
120
- content = self ._data .encode ()
121
- else :
122
- content = self ._data
123
- self ._file = _create_temp_file_with_content (
124
- base64 .standard_b64decode (content ), self ._temp_file_path )
125
- else :
126
- self ._file = _create_temp_file_with_content (
127
- self ._data , self ._temp_file_path )
118
+ self ._write_file ()
119
+
120
+ if self ._file and not os .path .isfile (self ._file ):
121
+ self ._write_file (force_rewrite = True )
128
122
if self ._file and not os .path .isfile (self ._file ):
129
123
raise ConfigException ("File does not exist: %s" % self ._file )
130
124
return self ._file
@@ -142,6 +136,18 @@ def as_data(self):
142
136
self ._data = f .read ()
143
137
return self ._data
144
138
139
+ def _write_file (self , force_rewrite = False ):
140
+ if self ._base64_file_content :
141
+ if isinstance (self ._data , str ):
142
+ content = self ._data .encode ()
143
+ else :
144
+ content = self ._data
145
+ self ._file = _create_temp_file_with_content (
146
+ base64 .standard_b64decode (content ), self ._temp_file_path , force_recreate = force_rewrite )
147
+ else :
148
+ self ._file = _create_temp_file_with_content (
149
+ self ._data , self ._temp_file_path , force_recreate = force_rewrite )
150
+
145
151
146
152
class CommandTokenSource (object ):
147
153
def __init__ (self , cmd , args , tokenKey , expiryKey ):
0 commit comments