Skip to content

Commit

Permalink
clean up the real temp dir only when zips are encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
rambo committed Jan 26, 2025
1 parent 80c3ea0 commit 63ba5e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/takrmapi/api/clientinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def client_instruction_fragment(user: UserCRUDRequest) -> List[Dict[str, s
"""Return zip package containing client config and certificates"""
localuser = tak_helpers.UserCRUD(user)
tak_missionpkg = tak_helpers.MissionZip(localuser)
zip_files = await tak_missionpkg.create_missionpkg()
zip_files, tmp_folder = await tak_missionpkg.create_missionpkg()
returnable: List[Dict[str, str]] = []
for file in zip_files:
with open(file, "rb") as filehandle:
Expand All @@ -33,4 +33,5 @@ async def client_instruction_fragment(user: UserCRUDRequest) -> List[Dict[str, s
"filename": f"{user.callsign}_{filename}",
}
)
await tak_missionpkg.helpers.remove_tmp_dir(str(tmp_folder))
return returnable
7 changes: 3 additions & 4 deletions src/takrmapi/tak_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Helper functions to manage tak"""

from typing import Any, Mapping, Union, Sequence, cast
from typing import Any, Mapping, Union, Sequence, cast, Tuple
import os
import asyncio
import shutil
Expand Down Expand Up @@ -180,7 +180,7 @@ def __init__(self, user: UserCRUD):
self.helpers = Helpers(self.user)
self.missionpkg = config.TAK_MISSIONPKG_DEFAULT_MISSION

async def create_missionpkg(self) -> list[str]:
async def create_missionpkg(self) -> Tuple[list[str], Path]:
"""Create tak mission package packages to different app versions"""
returnable: list[str] = []
# FIXME: Use Paths until absolutely have to convert to strings
Expand All @@ -195,8 +195,7 @@ async def create_missionpkg(self) -> list[str]:
if os.path.exists(f"{walk_dir}/wintak"):
zip_file = await self.create_mission_zip(tmp_folder, app_version="wintak", walk_dir=walk_dir / "wintak")
returnable.append(zip_file)
await self.helpers.remove_tmp_dir(str(tmp_folder))
return returnable
return returnable, tmp_folder

async def create_mission_zip( # pylint: disable=too-many-locals
self, tmp_base: Path, app_version: str, walk_dir: Path
Expand Down

0 comments on commit 63ba5e2

Please sign in to comment.