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

Fix mime checking when unix util "file" version <5. #1537

Conversation

jcoleman
Copy link

@jcoleman jcoleman commented May 5, 2014

This is potentially relevant in #1506, but it doesn't really affect the current choices, rather, it merely ensures that the current code works even on older versions of the file command on unix/linux.

For versions prior to 5, the -i option provides the mime type. That option doesn't exist in version 5 and has been replaced with the --mime that Paperclip was using by default.

@sikachu
Copy link
Contributor

sikachu commented May 9, 2014

This looks good. Would you mind adding these two test cases?

  • One that the major version less than 5 (preferably the output from version of file that Paperclip is incompatible).
  • One that's when the file command is missing.

Thank you so much for your patch.

@sikachu sikachu added this to the v4.1.2 milestone May 9, 2014
@djcp
Copy link
Contributor

djcp commented Jun 27, 2014

I like this idea, but maybe we should also look into memoizing the version check? Also, file 5 has been out since 2/4/2009 - what supported distros have file version 4 ?

http://mx.gw.com/pipermail/file/2009/000311.html

@jcoleman
Copy link
Author

@sikachu I'd forgotten about this, but the last comment just brought it back to my attention. Could you clarify what you want as a test case with your first request? As long as the correct flag/option is used, the output from the file command is identical, so I'm not exactly sure what the test case should test given that we can't easily test against both version of the file command.

@djcp I don't mind adding a simple cache so that we don't have to recheck every time, though technically I suppose that that could cause some odd issues in the unlikely chance that someone upgraded the file command while your app was running. As to the distros, I know the old version is still in CentOS 5.7. While I realize that's ancient, it's it's also true that quite a few shops/companies have to work with the fact that many places are incredibly slow to update distro versions.

@rubyisbeautiful
Copy link

+1
Thanks @jcoleman
This broke something for us. RHEL 5.10 still uses file 4.17 and so the new command line param breaks with the required spoof check.

@jcoleman
Copy link
Author

@sikachu I'm still waiting to hear back on what kind of test you'd like added here. I'm willing to add the test, but I'd like a bit of direction since the only test I can imagine would be an integration test that actually runs on different system with differing versions of the file command.

@cnk
Copy link

cnk commented Oct 21, 2014

@rubyisbeautiful I am running RHEL 5.11 which is claiming to have file 4.17 - but both -i and --mime work fine.

$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.11 (Tikanga)
$ file -b --mime 0586b599f017e259976b46739585299f20141020-26165-5322h.pdf
application/pdf
$ file -b -i 0586b599f017e259976b46739585299f20141020-26165-5322h.pdf
application/pdf

@maclover7
Copy link
Contributor

Hi everybody! Is this still an issue? If so, can you please rebase your PR and make sure everything is passing? Thanks!

@rubyisbeautiful
Copy link

@maclover7 It's no longer an issue for me/us, @cnk's findings are true for stock 5.10/5.11. I assume it was something weird with our environment on that project (wouldn't be the first time). Thanks!!

@maclover7
Copy link
Contributor

@jferris @jyurek Please close issue, problem appears to be solved.

@jcoleman
Copy link
Author

@maclover7 While I'm not personally affected by this anymore as we've moved to AWS (and a newer OS in the process), the code still has the same problem.

@jyurek jyurek closed this Apr 24, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants