From 909ed091f80c763f9da8ae6cca4f2a93e49d7a69 Mon Sep 17 00:00:00 2001 From: Matias Garcia Isaia Date: Thu, 1 Apr 2021 19:18:29 -0300 Subject: [PATCH] Drop mimemagic dependency See https://github.com/thoughtbot/paperclip/issues/2678 for context --- lib/paperclip.rb | 2 -- lib/paperclip/content_type_detector.rb | 7 +------ paperclip.gemspec | 1 - spec/paperclip/io_adapters/abstract_adapter_spec.rb | 1 - spec/paperclip/io_adapters/file_adapter_spec.rb | 2 -- 5 files changed, 1 insertion(+), 12 deletions(-) diff --git a/lib/paperclip.rb b/lib/paperclip.rb index 34b290f27..64d3431ec 100644 --- a/lib/paperclip.rb +++ b/lib/paperclip.rb @@ -64,8 +64,6 @@ require "mime/types" end -require 'mimemagic' -require 'mimemagic/overlay' require 'logger' require 'cocaine' diff --git a/lib/paperclip/content_type_detector.rb b/lib/paperclip/content_type_detector.rb index 782ed9e7c..9868823f1 100644 --- a/lib/paperclip/content_type_detector.rb +++ b/lib/paperclip/content_type_detector.rb @@ -60,17 +60,12 @@ def possible_types end def type_from_file_contents - type_from_mime_magic || type_from_file_command + type_from_file_command rescue Errno::ENOENT => e Paperclip.log("Error while determining content type: #{e}") SENSIBLE_DEFAULT end - def type_from_mime_magic - @type_from_mime_magic ||= - MimeMagic.by_magic(File.open(@filepath)).try(:type) - end - def type_from_file_command @type_from_file_command ||= FileCommandContentTypeDetector.new(@filepath).detect diff --git a/paperclip.gemspec b/paperclip.gemspec index 4aa4421c2..bd5b0573d 100644 --- a/paperclip.gemspec +++ b/paperclip.gemspec @@ -24,7 +24,6 @@ Gem::Specification.new do |s| s.add_dependency('activesupport', '>= 3.2.0') s.add_dependency('cocaine', '~> 0.5.5') s.add_dependency('mime-types') - s.add_dependency('mimemagic', '0.3.0') s.add_development_dependency('activerecord', '>= 3.2.0') s.add_development_dependency('shoulda') diff --git a/spec/paperclip/io_adapters/abstract_adapter_spec.rb b/spec/paperclip/io_adapters/abstract_adapter_spec.rb index eed4e2381..b1f1dae11 100644 --- a/spec/paperclip/io_adapters/abstract_adapter_spec.rb +++ b/spec/paperclip/io_adapters/abstract_adapter_spec.rb @@ -14,7 +14,6 @@ def content_type @adapter = TestAdapter.new @adapter.stubs(:path).returns("image.png") Paperclip.stubs(:run).returns("image/png\n") - Paperclip::ContentTypeDetector.any_instance.stubs(:type_from_mime_magic).returns("image/png") end it "returns the content type without newline" do diff --git a/spec/paperclip/io_adapters/file_adapter_spec.rb b/spec/paperclip/io_adapters/file_adapter_spec.rb index 42dd01de5..411b90a0b 100644 --- a/spec/paperclip/io_adapters/file_adapter_spec.rb +++ b/spec/paperclip/io_adapters/file_adapter_spec.rb @@ -77,8 +77,6 @@ before do MIME::Types.stubs(:type_for).returns([]) Paperclip.stubs(:run).returns("application/vnd.ms-office\n") - Paperclip::ContentTypeDetector.any_instance - .stubs(:type_from_mime_magic).returns("application/vnd.ms-office") @subject = Paperclip.io_adapters.for(@file) end