Skip to content

Commit

Permalink
Resolve file access conflict using mkstemp for ical download
Browse files Browse the repository at this point in the history
  • Loading branch information
mschabhuettl committed Oct 13, 2023
1 parent 2b13b1a commit 7926b1c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ def download_individual(person_name: str):
ical_content_encoded = ical_content.encode()

# Create a unique temporary ICS file and write the content
with tempfile.NamedTemporaryFile(delete=False, suffix=".ics", mode='wb', dir=TEMP_DIR) as temp_file:
fd, ics_path = tempfile.mkstemp(suffix=".ics", dir=TEMP_DIR)
with os.fdopen(fd, 'wb') as temp_file:
temp_file.write(ical_content_encoded)
ics_path = temp_file.name
temp_file.close() # Explicitly close the file

return send_file(ics_path, as_attachment=True, download_name=f"{filename}.ics")

Expand Down

0 comments on commit 7926b1c

Please sign in to comment.