Commit 1d22cdca by Jon Yurek

Gracefully handle a missing file command

parent 16f707ec
......@@ -49,8 +49,13 @@ module Paperclip
end
def type_from_file_command
type = begin
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
type = Paperclip.run("file", "-b --mime :file", :file => @filename)
Paperclip.run("file", "-b --mime :file", :file => @filename)
rescue Cocaine::CommandNotFoundError => e
SENSIBLE_DEFAULT
end
if type.match(/\(.*?\)/)
type = SENSIBLE_DEFAULT
end
......
......@@ -38,5 +38,11 @@ class ContentTypeDetectorTest < Test::Unit::TestCase
Paperclip::ContentTypeDetector.new(@filename).detect
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
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