Skip to content

Commit

Permalink
fix: do not use unreliable tempfile.TemporaryDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Apr 17, 2024
1 parent 9b04758 commit 6b667b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.15.3
- fix: do not use unreliable tempfile.TemporaryDirectory
0.15.2
- fix: attempt to create temporary condense location if not exists
0.15.1
Expand Down
13 changes: 11 additions & 2 deletions ckanext/dc_serve/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ def generate_condensed_resource_job(resource, override=False):
except BaseException:
cache_loc = None

with tempfile.TemporaryDirectory(dir=cache_loc) as ttd_name:
path_cond = pathlib.Path(ttd_name) / "condensed.rtdc"
if cache_loc is None:
cache_loc = tempfile.mkdtemp(prefix="ckanext-dc_serve_")

cache_loc = pathlib.Path(cache_loc)
path_cond = cache_loc / f"{rid}_condensed.rtdc"

try:
with CKANResourceFileLock(
resource_id=rid,
locker_id="DCOR_generate_condensed") as fl:
Expand Down Expand Up @@ -121,4 +126,8 @@ def generate_condensed_resource_job(resource, override=False):
artifact="condensed",
override=True)
return True
except BaseException:
pass
finally:
path_cond.unlink(missing_ok=True)
return False

0 comments on commit 6b667b7

Please sign in to comment.