Commit 1d22cdca by Jon Yurek

Gracefully handle a missing file command

parent 16f707ec
...@@ -49,8 +49,13 @@ module Paperclip ...@@ -49,8 +49,13 @@ module Paperclip
end end
def type_from_file_command def type_from_file_command
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist. type = begin
type = Paperclip.run("file", "-b --mime :file", :file => @filename) # On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
Paperclip.run("file", "-b --mime :file", :file => @filename)
rescue Cocaine::CommandNotFoundError => e
SENSIBLE_DEFAULT
end
if type.match(/\(.*?\)/) if type.match(/\(.*?\)/)
type = SENSIBLE_DEFAULT type = SENSIBLE_DEFAULT
end end
......
...@@ -38,5 +38,11 @@ class ContentTypeDetectorTest < Test::Unit::TestCase ...@@ -38,5 +38,11 @@ class ContentTypeDetectorTest < Test::Unit::TestCase
Paperclip::ContentTypeDetector.new(@filename).detect Paperclip::ContentTypeDetector.new(@filename).detect
end end
end end
should 'return a sensible default when the file command is missing' do
Paperclip.stubs(:run).raises(Cocaine::CommandNotFoundError.new)
@filename = "/path/to/something"
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment