From 02dbe64283199a1a75bb7f5d64dc01f5b9888aaa Mon Sep 17 00:00:00 2001 From: Marc Shaw <mshaw@gitlab.com> Date: Thu, 25 Mar 2021 14:46:52 +1300 Subject: [PATCH] Create a fake mimemagic gem Issue: gitlab.com/gitlab-org/gitlab/-/issues/325851 MR: gitlab.com/gitlab-org/gitlab/-/merge_requests/57443 There is a current issue affecting mimemagic where it was using a magic number dataset which turned out to be under a GPL licence, which in turn meant the maintainer of mimemagic had to switch to the same licence. We can not use this licence. There are still dependencies in our gemfile which require mimemagic, and instead of removing all these, we create a fake gem that we require. --- Gemfile | 3 +++ Gemfile.lock | 7 ++++++- changelogs/unreleased/mimemagic_shim.yml | 5 +++++ vendor/shims/mimemagic/Gemfile | 6 ++++++ vendor/shims/mimemagic/LICENSE.txt | 21 +++++++++++++++++++ vendor/shims/mimemagic/README.md | 1 + vendor/shims/mimemagic/Rakefile | 2 ++ vendor/shims/mimemagic/lib/mimemagic.rb | 6 ++++++ .../shims/mimemagic/lib/mimemagic/version.rb | 3 +++ vendor/shims/mimemagic/mimemagic.gemspec | 20 ++++++++++++++++++ 10 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/mimemagic_shim.yml create mode 100644 vendor/shims/mimemagic/Gemfile create mode 100644 vendor/shims/mimemagic/LICENSE.txt create mode 100644 vendor/shims/mimemagic/README.md create mode 100644 vendor/shims/mimemagic/Rakefile create mode 100644 vendor/shims/mimemagic/lib/mimemagic.rb create mode 100644 vendor/shims/mimemagic/lib/mimemagic/version.rb create mode 100644 vendor/shims/mimemagic/mimemagic.gemspec diff --git a/Gemfile b/Gemfile index abd3efa6dfbf3..4924401c7c56d 100644 --- a/Gemfile +++ b/Gemfile @@ -276,6 +276,9 @@ gem 'charlock_holmes', '~> 0.7.7' # Detect mime content type from content gem 'ruby-magic', '~> 0.3' +# Fake version of the gem to trick bundler +gem 'mimemagic', '0.3.5', path: 'vendor/shims/mimemagic', require: false + # Faster blank gem 'fast_blank' diff --git a/Gemfile.lock b/Gemfile.lock index ef184e94bf15d..7a4101d538200 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,8 @@ +PATH + remote: vendor/shims/mimemagic + specs: + mimemagic (0.3.5) + GEM remote: https://rubygems.org/ specs: @@ -728,7 +733,6 @@ GEM mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2020.0512) - mimemagic (0.3.5) mini_histogram (0.3.1) mini_magick (4.10.1) mini_mime (1.0.2) @@ -1482,6 +1486,7 @@ DEPENDENCIES marginalia (~> 1.10.0) memory_profiler (~> 0.9) method_source (~> 1.0) + mimemagic (= 0.3.5)! mini_magick (~> 4.10.1) minitest (~> 5.11.0) multi_json (~> 1.14.1) diff --git a/changelogs/unreleased/mimemagic_shim.yml b/changelogs/unreleased/mimemagic_shim.yml new file mode 100644 index 0000000000000..0376122f0ce83 --- /dev/null +++ b/changelogs/unreleased/mimemagic_shim.yml @@ -0,0 +1,5 @@ +--- +title: Switch to using a fake mimemagic gem +merge_request: 57443 +author: +type: other diff --git a/vendor/shims/mimemagic/Gemfile b/vendor/shims/mimemagic/Gemfile new file mode 100644 index 0000000000000..ef48903d33444 --- /dev/null +++ b/vendor/shims/mimemagic/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in mimemagic.gemspec +gemspec + +gem "rake", "~> 12.0" diff --git a/vendor/shims/mimemagic/LICENSE.txt b/vendor/shims/mimemagic/LICENSE.txt new file mode 100644 index 0000000000000..568df6132bc97 --- /dev/null +++ b/vendor/shims/mimemagic/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2021 GitLab B.V. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/shims/mimemagic/README.md b/vendor/shims/mimemagic/README.md new file mode 100644 index 0000000000000..57ef8dc41e1e1 --- /dev/null +++ b/vendor/shims/mimemagic/README.md @@ -0,0 +1 @@ +This is a fake gem to prevent mimemagic from being included into GitLab. diff --git a/vendor/shims/mimemagic/Rakefile b/vendor/shims/mimemagic/Rakefile new file mode 100644 index 0000000000000..43022f711e20e --- /dev/null +++ b/vendor/shims/mimemagic/Rakefile @@ -0,0 +1,2 @@ +require "bundler/gem_tasks" +task :default => :spec diff --git a/vendor/shims/mimemagic/lib/mimemagic.rb b/vendor/shims/mimemagic/lib/mimemagic.rb new file mode 100644 index 0000000000000..1deab5d90a7b9 --- /dev/null +++ b/vendor/shims/mimemagic/lib/mimemagic.rb @@ -0,0 +1,6 @@ +require "mimemagic/version" + +module MimeMagic + class Error < StandardError; end + raise Error, 'This gem should never be required' +end diff --git a/vendor/shims/mimemagic/lib/mimemagic/version.rb b/vendor/shims/mimemagic/lib/mimemagic/version.rb new file mode 100644 index 0000000000000..fb46494748a69 --- /dev/null +++ b/vendor/shims/mimemagic/lib/mimemagic/version.rb @@ -0,0 +1,3 @@ +module MimeMagic + VERSION = "0.3.5" +end diff --git a/vendor/shims/mimemagic/mimemagic.gemspec b/vendor/shims/mimemagic/mimemagic.gemspec new file mode 100644 index 0000000000000..3b92efd621908 --- /dev/null +++ b/vendor/shims/mimemagic/mimemagic.gemspec @@ -0,0 +1,20 @@ +require_relative 'lib/mimemagic/version' + +Gem::Specification.new do |spec| + spec.name = "mimemagic" + spec.version = MimeMagic::VERSION + spec.authors = ["Marc Shaw"] + spec.email = ["mshaw@gitlab.com"] + + spec.summary = %q{MimeMagic shim} + spec.description = %q{A shim for mimemagic} + spec.license = "MIT" + spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0") + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + end + spec.require_paths = ["lib"] +end -- GitLab