Skip to content

Commit

Permalink
metadata: no need to use tempdir
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Dec 11, 2024
1 parent 1ebd396 commit 4a0a9c3
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/ota_metadata/legacy/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4a0a9c3

Please sign in to comment.