diff --git a/commonlibrary/toolchain/libc-test/tar_files.py b/commonlibrary/toolchain/libc-test/tar_files.py index 1d745e6ebde81d5cf6df0be7c828ca0e9f9719f8..356f7f2eed42641d14ee801405841fbc579984aa 100755 --- a/commonlibrary/toolchain/libc-test/tar_files.py +++ b/commonlibrary/toolchain/libc-test/tar_files.py @@ -30,14 +30,16 @@ def copyFiles(sourceDir, targetDir): if not os.path.isfile(sourceF): if os.path.isdir(sourceF): copyFiles(sourceF, targetF) - elif os.path.isfile(sourceF): - if os.path.exists(targetDir): - copyFileCounts += 1 - open(targetF, "wb").write(open(sourceF, "rb").read()) - elif not os.path.exists(targetDir): - os.makedirs(targetDir) - copyFileCounts += 1 - open(targetF, "wb").write(open(sourceF, "rb").read()) + continue + if os.path.exists(targetDir): + copyFileCounts += 1 + with open(targetF, "wb") as target_open: + target_open.write(open(sourceF, "rb").read()) + elif not os.path.exists(targetDir): + os.makedirs(targetDir) + copyFileCounts += 1 + with open(targetF, "wb") as target_open: + target_open.write(open(sourceF, "rb").read()) def make_targz_one_by_one(output_filename, source_dir): tar = tarfile.open(output_filename,"w")