From 0a9e5df66cf24b5d5d7a22847f9541d177816579 Mon Sep 17 00:00:00 2001 From: Stepan Oksanichenko Date: Fri, 10 Nov 2023 21:38:01 +0200 Subject: [PATCH] - Properly removing tmp files --- pungi/scripts/create_packages_json.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pungi/scripts/create_packages_json.py b/pungi/scripts/create_packages_json.py index 23bbd4a2..c0571d37 100644 --- a/pungi/scripts/create_packages_json.py +++ b/pungi/scripts/create_packages_json.py @@ -118,15 +118,15 @@ class PackagesGenerator: self.pkgs = dict() self.excluded_packages = excluded_packages self.included_packages = included_packages - self.tmp_files = [] + self.tmp_files = [] # type: list[Path] for arch, arch_list in self.addon_repos.items(): self.repo_arches[arch].extend(arch_list) self.repo_arches[arch].append(arch) def __del__(self): for tmp_file in self.tmp_files: - if os.path.exists(tmp_file): - os.remove(tmp_file) + if tmp_file.exists(): + tmp_file.unlink() @staticmethod def _get_full_repo_path(repo_info: RepoInfo): @@ -149,8 +149,7 @@ class PackagesGenerator: print(f'Warning message: "{message}"; warning type: "{warning_type}"') return True - @staticmethod - def get_remote_file_content(file_url: AnyStr) -> AnyStr: + def get_remote_file_content(self, file_url: AnyStr) -> AnyStr: """ Get content from a remote file and write it to a temp file :param file_url: url of a remote file @@ -163,6 +162,7 @@ class PackagesGenerator: file_request.raise_for_status() with tempfile.NamedTemporaryFile(delete=False) as file_stream: file_stream.write(file_request.content) + self.tmp_files.append(Path(file_stream.name)) return file_stream.name @staticmethod @@ -253,7 +253,6 @@ class PackagesGenerator: if repo_info.is_remote: repomd_record_file_path = self.get_remote_file_content( repomd_record_file_path) - self.tmp_files.append(repomd_record_file_path) repomd_records_dict[repomd_record.type] = repomd_record_file_path def _parse_module_repomd_record( @@ -277,7 +276,6 @@ class PackagesGenerator: if repo_info.is_remote: repomd_record_file_path = self.get_remote_file_content( repomd_record_file_path) - self.tmp_files.append(repomd_record_file_path) return list(self._parse_modules_file( repomd_record_file_path, ))