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

set summarizer write to tempfile #330

Merged
merged 2 commits into from
Apr 24, 2024
Merged

Conversation

MichaelClifford
Copy link
Collaborator

Follow up to #302

Noticed summarizer was having write issues in container. Using the /tmp/ directory should address it.

Signed-off-by: Michael Clifford <[email protected]>
@Gregory-Pereira
Copy link
Collaborator

Similar issue encountered in: #307 but this solves it a better way

Copy link
Collaborator

@Gregory-Pereira Gregory-Pereira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@rhatdan
Copy link
Member

rhatdan commented Apr 24, 2024

There is security risks in writing to tmp, can you use a tmpfile name rather then a hard coded file name?

Signed-off-by: Michael Clifford <[email protected]>
@MichaelClifford MichaelClifford changed the title set summarizer write to /tmp set summarizer write to tempfile Apr 24, 2024
@MichaelClifford
Copy link
Collaborator Author

Thanks @rhatdan Changed it to use a tempfile instead.

@@ -49,12 +50,12 @@ def read_file(file):
file_type = file.type

if file_type == "application/pdf":
with open(file.name, "wb") as f:
temp = tempfile.NamedTemporaryFile()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to remove this when you are done with it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tested it the tempfile deleted after the file was no longer being used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this some magic in Python?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the [tempfile module](http://docs.python.org/2/library/tempfile.html); it creates temporary files that auto-delete.

From the [tempfile.NamedTemporaryFile() documentation](http://docs.python.org/2/library/tempfile.html#tempfile.NamedTemporaryFile):

    If delete is true (the default), the file is deleted as soon as it is closed.

Cool

@rhatdan
Copy link
Member

rhatdan commented Apr 24, 2024

LGTM

@rhatdan rhatdan merged commit 0109d08 into containers:main Apr 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants