1313See the License for the specific language governing permissions and
1414limitations under the License.
1515"""
16- from charon .utils .files import digest , HashType
16+ from charon .utils .files import digest , HashType , overwrite_file
1717from charon .storage import S3Client
1818from typing import Tuple , List , Dict , Optional
1919from html .parser import HTMLParser
@@ -169,9 +169,10 @@ def _check_and_remove_file(file_name: str):
169169 def _write_one_col_file (items : List [str ], file_name : str ):
170170 if items and len (items ) > 0 :
171171 _check_and_remove_file (file_name )
172- with open (file_name , "w" ) as f :
173- for i in items :
174- f .write (i + "\n " )
172+ content = ""
173+ for i in items :
174+ content = content + i + "\n "
175+ overwrite_file (file_name , content )
175176 logger .info ("The report file %s is generated." , file_name )
176177
177178 _write_one_col_file (content [0 ], os .path .join (work_dir , "mismatched_files.csv" ))
@@ -180,10 +181,9 @@ def _write_one_col_file(items: List[str], file_name: str):
180181 if content [2 ] and len (content [2 ]) > 0 :
181182 error_file = os .path .join (work_dir , "error_files.csv" )
182183 _check_and_remove_file (error_file )
183- with open (error_file , "w" ) as f :
184- f .write ("path,error\n " )
185- for d in content [2 ]:
186- f .write ("{path},{error}\n " .format (path = d ["path" ], error = d ["error" ]))
184+ f_content_lines : List [str ] = []
185+ f_content = "path,error\n " + "\n " .join (f_content_lines )
186+ overwrite_file (error_file , f_content )
187187 logger .info ("The report file %s is generated." , error_file )
188188
189189
0 commit comments