Commit a9dab953 authored by Brett Walker's avatar Brett Walker Committed by Luke Duncalfe

Use ruby-magic gem instead of mimemagic gem

due to licensing issues
parent f31e6437
...@@ -274,7 +274,7 @@ gem 'licensee', '~> 9.14.1' ...@@ -274,7 +274,7 @@ gem 'licensee', '~> 9.14.1'
gem 'charlock_holmes', '~> 0.7.7' gem 'charlock_holmes', '~> 0.7.7'
# Detect mime content type from content # Detect mime content type from content
gem 'mimemagic', '~> 0.3.2' gem 'ruby-magic'
# Faster blank # Faster blank
gem 'fast_blank' gem 'fast_blank'
......
...@@ -1109,6 +1109,7 @@ GEM ...@@ -1109,6 +1109,7 @@ GEM
i18n i18n
ruby-fogbugz (0.2.1) ruby-fogbugz (0.2.1)
crack (~> 0.4) crack (~> 0.4)
ruby-magic (0.2.0)
ruby-prof (1.3.1) ruby-prof (1.3.1)
ruby-progressbar (1.11.0) ruby-progressbar (1.11.0)
ruby-saml (1.7.2) ruby-saml (1.7.2)
...@@ -1481,7 +1482,6 @@ DEPENDENCIES ...@@ -1481,7 +1482,6 @@ DEPENDENCIES
marginalia (~> 1.10.0) marginalia (~> 1.10.0)
memory_profiler (~> 0.9) memory_profiler (~> 0.9)
method_source (~> 1.0) method_source (~> 1.0)
mimemagic (~> 0.3.2)
mini_magick (~> 4.10.1) mini_magick (~> 4.10.1)
minitest (~> 5.11.0) minitest (~> 5.11.0)
multi_json (~> 1.14.1) multi_json (~> 1.14.1)
...@@ -1555,6 +1555,7 @@ DEPENDENCIES ...@@ -1555,6 +1555,7 @@ DEPENDENCIES
rspec_junit_formatter rspec_junit_formatter
rspec_profiling (~> 0.0.6) rspec_profiling (~> 0.0.6)
ruby-fogbugz (~> 0.2.1) ruby-fogbugz (~> 0.2.1)
ruby-magic
ruby-prof (~> 1.3.0) ruby-prof (~> 1.3.0)
ruby-progressbar (~> 1.10) ruby-progressbar (~> 1.10)
ruby_parser (~> 3.15) ruby_parser (~> 3.15)
......
---
title: Remove direct mimemagic dependency
merge_request: 57387
author:
type: other
# frozen_string_literal: true # frozen_string_literal: true
require 'magic'
# This wraps calls to a gem which support mime type detection. # This wraps calls to a gem which support mime type detection.
# Currently uses `mimemagic`, but that will be replaced shortly. # We use the `ruby-magic` gem instead of `mimemagic` due to licensing issues
module Gitlab module Gitlab
module Utils module Utils
class MimeType class MimeType
...@@ -9,13 +10,14 @@ module Gitlab ...@@ -9,13 +10,14 @@ module Gitlab
def from_io(io) def from_io(io)
return unless io.is_a?(IO) || io.is_a?(StringIO) return unless io.is_a?(IO) || io.is_a?(StringIO)
MimeMagic.by_magic(io).try(:type) mime_type = File.magic(io, Magic::MIME_TYPE)
mime_type == 'inode/x-empty' ? nil : mime_type
end end
def from_string(string) def from_string(string)
return unless string.is_a?(String) return unless string.is_a?(String)
MimeMagic.by_magic(string) string.type
end end
end end
end end
......
...@@ -24,7 +24,7 @@ RSpec.describe Gitlab::Utils::MimeType do ...@@ -24,7 +24,7 @@ RSpec.describe Gitlab::Utils::MimeType do
"rails_sample.png" | "image/png" "rails_sample.png" | "image/png"
"rails_sample.bmp" | "image/bmp" "rails_sample.bmp" | "image/bmp"
"rails_sample.tif" | "image/tiff" "rails_sample.tif" | "image/tiff"
"blockquote_fence_before.md" | nil "blockquote_fence_before.md" | "text/plain"
"csv_empty.csv" | nil "csv_empty.csv" | nil
end end
...@@ -50,7 +50,7 @@ RSpec.describe Gitlab::Utils::MimeType do ...@@ -50,7 +50,7 @@ RSpec.describe Gitlab::Utils::MimeType do
context "input is a string" do context "input is a string" do
let(:str) { "plain text" } let(:str) { "plain text" }
it { is_expected.to eq(nil) } it { is_expected.to eq('text/plain') }
end 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