From 4a0a9c387d415602bf4a82c5f04320f759fbe371 Mon Sep 17 00:00:00 2001 From: "bodong.yang" Date: Tue, 10 Dec 2024 16:56:34 +0000 Subject: [PATCH] metadata: no need to use tempdir --- src/ota_metadata/legacy/metadata.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/ota_metadata/legacy/metadata.py b/src/ota_metadata/legacy/metadata.py index 43de259c7..678a5fe09 100644 --- a/src/ota_metadata/legacy/metadata.py +++ b/src/ota_metadata/legacy/metadata.py @@ -44,7 +44,6 @@ import shutil import sqlite3 from pathlib import Path -from tempfile import TemporaryDirectory from typing import Generator from urllib.parse import quote @@ -152,10 +151,8 @@ def __init__( self._work_dir = wd = Path(work_dir) wd.mkdir(exist_ok=True, parents=True) - self._download_tmp = download_tmp = TemporaryDirectory( - dir=work_dir, prefix=".download", suffix=os.urandom(8).hex() - ) - self._download_folder = Path(download_tmp.name) + self._download_folder = df = Path(work_dir) / f".download_{os.urandom(4).hex()}" + df.mkdir(exist_ok=True, parents=True) self._metadata_jwt = None self._total_regulars_num = 0 @@ -270,7 +267,7 @@ def download_metafiles(self) -> Generator[DownloadInfo, None, None]: _persist_meta = self._download_folder / _metadata_jwt.persistent.file shutil.move(str(_persist_meta), self._work_dir / self.PERSIST_FNAME) finally: - self._download_tmp.cleanup() + shutil.rmtree(self._download_folder, ignore_errors=True) def iter_persist_entries(self) -> Generator[str, None, None]: _persist_fpath = self._work_dir / self.PERSIST_FNAME