Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Content type detection locks original file #2016

Closed
daniel-rikowski opened this issue Sep 29, 2015 · 4 comments · Fixed by #2205
Closed

Content type detection locks original file #2016

daniel-rikowski opened this issue Sep 29, 2015 · 4 comments · Fixed by #2205

Comments

@daniel-rikowski
Copy link

Paperclip::ContentTypeDetector keeps a File object open and thus prevents it from being deleted, moved, etc. until it is closed by the garbage collector.

I was mass-importing images from a zip file and I noticed that I couldn't delete the files after assigning them to Paperclip.

In line 71:

MimeMagic.by_magic(File.open(@filepath)).try(:type)

... the open file is not closed.

Although this problem is unrelated to #1759, #1980 or #1326, it might very well worsen those situations.

IMHO that line should be:

File.open(@filepath) { |f| MimeMagic.by_magic(f).try(:type) }

Shall I make a pull request?

@aouji
Copy link

aouji commented Jan 8, 2016

Any news on this one? It seems to be a safe change and reduces the number of file objects paperclip leaves behind open.

@tute
Copy link
Contributor

tute commented May 10, 2016

IMHO that line should be:

File.open(@filepath) { |f| MimeMagic.by_magic(f).try(:type) }

Shall I make a pull request?

Please do. Great catch, thanks!

@tute
Copy link
Contributor

tute commented May 10, 2016

Already fixed. Thank you!

@daniel-rikowski
Copy link
Author

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants