Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid leaving uncleaned up deleted temp files #31

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Avoid leaving uncleaned up deleted temp files
  • Loading branch information
jrdh committed Jun 6, 2022
commit 5fe53283296e47ad63b476d6c20bc0dd6f2436df
18 changes: 6 additions & 12 deletions iiif/profiles/mss.py
Original file line number Diff line number Diff line change
@@ -489,18 +489,12 @@ async def _fetch(self, source: MSSSourceFile):
f.write(chunk)
f.flush()

# convert the image file, saving the data in a temp file but then moving it
# to the source_path after the conversion is complete
with tempfile.NamedTemporaryFile(delete=False) as g:
target_path = Path(g.name)

pool = self._choose_convert_pool(source.file)
convert = partial(self._convert, image_path, target_path)
await asyncio.get_running_loop().run_in_executor(pool, convert)

cache_path = self.root / source.store_path
cache_path.parent.mkdir(parents=True, exist_ok=True)
shutil.move(target_path, cache_path)
# the later IIIF ops stage expects a JPEG image so convert the source image to JPEG here
pool = self._choose_convert_pool(source.file)
cache_path = self.root / source.store_path
cache_path.parent.mkdir(parents=True, exist_ok=True)
convert = partial(self._convert, image_path, cache_path)
await asyncio.get_running_loop().run_in_executor(pool, convert)

@asynccontextmanager
async def _open_stream(self, source: MSSSourceFile) -> ClientResponse: