diff -Nru ruby-marcel-0.3.2/debian/changelog ruby-marcel-1.0.1+dfsg/debian/changelog --- ruby-marcel-0.3.2/debian/changelog 2020-08-28 13:53:14.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/debian/changelog 2021-05-15 16:11:46.000000000 +0530 @@ -1,3 +1,29 @@ +ruby-marcel (1.0.1+dfsg-2) unstable; urgency=medium + + * Team upload. + * Upload to unstable. + + -- Utkarsh Gupta Sat, 15 May 2021 16:12:21 +0530 + +ruby-marcel (1.0.1+dfsg-1) experimental; urgency=medium + + * Team upload + * Add lintian overrides for test data + * Bump Standards-Version to 4.5.1 (no changes needed) + * Switch to github for source + * New upstream version 1.0.1 + The mimemagic dependency—which relies on GPL-licensed mime type data from + freedesktop.org’s shared-mime-info project—is removed. Marcel now directly + uses mime type data adapted from the Apache Tika project, distributed under + the Apache License. + * Generate tables during build + * New upstream version 1.0.1+dfsg (exclude generated tables) + * Refresh patches + * Update (build) dependencies + * Update copyright for data/tika.xml + + -- Pirate Praveen Thu, 29 Apr 2021 16:36:46 +0530 + ruby-marcel (0.3.2-4) unstable; urgency=medium * Team upload diff -Nru ruby-marcel-0.3.2/debian/control ruby-marcel-1.0.1+dfsg/debian/control --- ruby-marcel-0.3.2/debian/control 2020-08-28 13:53:14.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/debian/control 2021-05-15 16:09:20.000000000 +0530 @@ -7,8 +7,9 @@ gem2deb (>= 1), rake, ruby-rack, - ruby-mimemagic (>= 0.3.2) -Standards-Version: 4.5.0 + ruby-nokogiri, + ruby-byebug +Standards-Version: 4.5.1 Vcs-Git: https://salsa.debian.org/ruby-team/ruby-marcel.git Vcs-Browser: https://salsa.debian.org/ruby-team/ruby-marcel Homepage: https://github.com/basecamp/marcel @@ -19,8 +20,7 @@ Package: ruby-marcel Architecture: all XB-Ruby-Versions: ${ruby:Versions} -Depends: ruby-mimemagic (>= 0.3.2), - ${misc:Depends}, +Depends: ${misc:Depends}, ${ruby:Depends}, ${shlibs:Depends} Description: Simple mime type detection diff -Nru ruby-marcel-0.3.2/debian/copyright ruby-marcel-1.0.1+dfsg/debian/copyright --- ruby-marcel-0.3.2/debian/copyright 2020-08-28 13:53:14.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/debian/copyright 2021-05-15 16:09:20.000000000 +0530 @@ -1,11 +1,16 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: marcel Source: https://github.com/basecamp/marcel +Files-Excluded: lib/marcel/tables.rb Files: * Copyright: 2017 Tom Ward License: Expat +Files: data/tika.xml +Copyright: The Apache Software Foundation (ASF) +License: Apache-2.0 + Files: debian/* Copyright: 2018 Sruthi Chandran License: Expat @@ -30,3 +35,21 @@ 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. + +License: Apache-2.0 + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + . + http://www.apache.org/licenses/LICENSE-2.0 + . + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + . + On Debian systems, the full text of the Apache License, Version 2.0 + can be found in the file `/usr/share/common-licenses/Apache-2.0'. + + diff -Nru ruby-marcel-0.3.2/debian/patches/0002-skip-ttf-fixtures.patch ruby-marcel-1.0.1+dfsg/debian/patches/0002-skip-ttf-fixtures.patch --- ruby-marcel-0.3.2/debian/patches/0002-skip-ttf-fixtures.patch 2020-08-28 13:53:14.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/debian/patches/0002-skip-ttf-fixtures.patch 2021-05-15 16:09:20.000000000 +0530 @@ -8,11 +8,9 @@ test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -diff --git a/test/test_helper.rb b/test/test_helper.rb -index 6eb2dc0..5f34d05 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb -@@ -33,7 +33,7 @@ class Marcel::TestCase < MiniTest::Test +@@ -35,7 +35,7 @@ if File.file?(name) _, content_type, extra, extension = *name.match(/\A([^\/]+\/[^\/]*)\/?(.*)\.(\w+)\Z/) extra = nil if content_type[-content_type.size..-1] == extra diff -Nru ruby-marcel-0.3.2/debian/patches/require-pathname.patch ruby-marcel-1.0.1+dfsg/debian/patches/require-pathname.patch --- ruby-marcel-0.3.2/debian/patches/require-pathname.patch 2020-08-28 13:53:14.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/debian/patches/require-pathname.patch 1970-01-01 05:30:00.000000000 +0530 @@ -1,20 +0,0 @@ -From: Debian Ruby Team -Date: Fri, 28 Aug 2020 10:17:56 +0200 -Subject: require-pathname - -require pathname explicitly ---- - test/test_helper.rb | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/test/test_helper.rb b/test/test_helper.rb -index 21066d5..6eb2dc0 100644 ---- a/test/test_helper.rb -+++ b/test/test_helper.rb -@@ -1,5 +1,6 @@ - require 'minitest/autorun' - require 'marcel' -+require 'pathname' - - class Marcel::TestCase < MiniTest::Test - class << self diff -Nru ruby-marcel-0.3.2/debian/patches/series ruby-marcel-1.0.1+dfsg/debian/patches/series --- ruby-marcel-0.3.2/debian/patches/series 2020-08-28 13:53:14.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/debian/patches/series 2021-05-15 16:09:20.000000000 +0530 @@ -1,2 +1 @@ -require-pathname.patch 0002-skip-ttf-fixtures.patch diff -Nru ruby-marcel-0.3.2/debian/rules ruby-marcel-1.0.1+dfsg/debian/rules --- ruby-marcel-0.3.2/debian/rules 2020-08-28 13:53:14.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/debian/rules 2021-05-15 16:09:20.000000000 +0530 @@ -5,3 +5,7 @@ %: dh $@ --buildsystem=ruby --with ruby + +override_dh_auto_build: + rake tables + dh_auto_build diff -Nru ruby-marcel-0.3.2/debian/salsa-ci.yml ruby-marcel-1.0.1+dfsg/debian/salsa-ci.yml --- ruby-marcel-0.3.2/debian/salsa-ci.yml 1970-01-01 05:30:00.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/debian/salsa-ci.yml 2021-05-15 16:09:20.000000000 +0530 @@ -0,0 +1,4 @@ +--- +include: + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml diff -Nru ruby-marcel-0.3.2/debian/source/lintian-overrides ruby-marcel-1.0.1+dfsg/debian/source/lintian-overrides --- ruby-marcel-0.3.2/debian/source/lintian-overrides 1970-01-01 05:30:00.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/debian/source/lintian-overrides 2021-05-15 16:09:20.000000000 +0530 @@ -0,0 +1,3 @@ +# test data +ruby-marcel source: source-is-missing test/fixtures/magic/application/vnd.adobe.flash.movie/flash.swf +ruby-marcel source: source-is-missing test/fixtures/name/application/vnd.adobe.flash.movie/flash.swf diff -Nru ruby-marcel-0.3.2/debian/watch ruby-marcel-1.0.1+dfsg/debian/watch --- ruby-marcel-0.3.2/debian/watch 2020-08-28 13:53:14.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/debian/watch 2021-05-15 16:09:20.000000000 +0530 @@ -1,2 +1,5 @@ version=4 -https://gemwatch.debian.net/marcel .*/marcel-(.*).tar.gz +opts=\ +dversionmangle=auto,repack,compression=xz,repacksuffix=+dfsg,\ +filenamemangle=s/.*\/v?([\d\.-]+)\.tar\.gz/ruby-marcel-$1.tar.gz/ \ + https://github.com/rails/marcel/releases .*/archive/.*/v?([\d\.]+).tar.gz group diff -Nru ruby-marcel-0.3.2/lib/marcel/magic.rb ruby-marcel-1.0.1+dfsg/lib/marcel/magic.rb --- ruby-marcel-0.3.2/lib/marcel/magic.rb 1970-01-01 05:30:00.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/lib/marcel/magic.rb 2021-04-02 18:30:30.000000000 +0530 @@ -0,0 +1,147 @@ +# frozen_string_literal: true + +# Code in this file adapted from the mimemagic gem, released under the MIT License. +# Copyright (c) 2011 Daniel Mendler. Available at https://github.com/mimemagicrb/mimemagic. + +require 'marcel/tables' + +require 'stringio' + +module Marcel + # Mime type detection + class Magic + attr_reader :type, :mediatype, :subtype + + # Mime type by type string + def initialize(type) + @type = type + @mediatype, @subtype = type.split('/', 2) + end + + # Add custom mime type. Arguments: + # * type: Mime type + # * options: Options hash + # + # Option keys: + # * :extensions: String list or single string of file extensions + # * :parents: String list or single string of parent mime types + # * :magic: Mime magic specification + # * :comment: Comment string + def self.add(type, options) + extensions = [options[:extensions]].flatten.compact + TYPES[type] = [extensions, + [options[:parents]].flatten.compact, + options[:comment]] + extensions.each {|ext| EXTENSIONS[ext] = type } + MAGIC.unshift [type, options[:magic]] if options[:magic] + end + + # Removes a mime type from the dictionary. You might want to do this if + # you're seeing impossible conflicts (for instance, application/x-gmc-link). + # * type: The mime type to remove. All associated extensions and magic are removed too. + def self.remove(type) + EXTENSIONS.delete_if {|ext, t| t == type } + MAGIC.delete_if {|t, m| t == type } + TYPES.delete(type) + end + + # Returns true if type is a text format + def text?; mediatype == 'text' || child_of?('text/plain'); end + + # Mediatype shortcuts + def image?; mediatype == 'image'; end + def audio?; mediatype == 'audio'; end + def video?; mediatype == 'video'; end + + # Returns true if type is child of parent type + def child_of?(parent) + self.class.child?(type, parent) + end + + # Get string list of file extensions + def extensions + TYPES.key?(type) ? TYPES[type][0] : [] + end + + # Get mime comment + def comment + (TYPES.key?(type) ? TYPES[type][2] : nil).to_s + end + + # Lookup mime type by file extension + def self.by_extension(ext) + ext = ext.to_s.downcase + mime = ext[0..0] == '.' ? EXTENSIONS[ext[1..-1]] : EXTENSIONS[ext] + mime && new(mime) + end + + # Lookup mime type by filename + def self.by_path(path) + by_extension(File.extname(path)) + end + + # Lookup mime type by magic content analysis. + # This is a slow operation. + def self.by_magic(io) + mime = magic_match(io, :find) + mime && new(mime[0]) + end + + # Lookup all mime types by magic content analysis. + # This is a slower operation. + def self.all_by_magic(io) + magic_match(io, :select).map { |mime| new(mime[0]) } + end + + # Return type as string + def to_s + type + end + + # Allow comparison with string + def eql?(other) + type == other.to_s + end + + def hash + type.hash + end + + alias == eql? + + def self.child?(child, parent) + child == parent || TYPES.key?(child) && TYPES[child][1].any? {|p| child?(p, parent) } + end + + def self.magic_match(io, method) + return magic_match(StringIO.new(io.to_s), method) unless io.respond_to?(:read) + + io.binmode if io.respond_to?(:binmode) + io.set_encoding(Encoding::BINARY) if io.respond_to?(:set_encoding) + buffer = "".encode(Encoding::BINARY) + + MAGIC.send(method) { |type, matches| magic_match_io(io, matches, buffer) } + end + + def self.magic_match_io(io, matches, buffer) + matches.any? do |offset, value, children| + match = + if value + if Range === offset + io.read(offset.begin, buffer) + x = io.read(offset.end - offset.begin + value.bytesize, buffer) + x && x.include?(value) + else + io.read(offset, buffer) + io.read(value.bytesize, buffer) == value + end + end + + io.rewind + match && (!children || magic_match_io(io, children, buffer)) + end + end + + private_class_method :magic_match, :magic_match_io + end +end diff -Nru ruby-marcel-0.3.2/lib/marcel/mime_type/definitions.rb ruby-marcel-1.0.1+dfsg/lib/marcel/mime_type/definitions.rb --- ruby-marcel-0.3.2/lib/marcel/mime_type/definitions.rb 2018-05-02 13:02:52.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/lib/marcel/mime_type/definitions.rb 2021-04-02 18:30:30.000000000 +0530 @@ -1,6 +1,3 @@ -require 'mimemagic' -require 'mimemagic/overlay' - Marcel::MimeType.extend "text/plain", extensions: %w( txt asc ) Marcel::MimeType.extend "application/illustrator", parents: "application/pdf" @@ -37,3 +34,11 @@ Marcel::MimeType.extend "image/heif", magic: [[4, "ftypmif1"]], extensions: %w( heif ) Marcel::MimeType.extend "image/heic", magic: [[4, "ftypheic"]], extensions: %w( heic ) + +Marcel::MimeType.extend "video/mp4", magic: [[4, "ftypisom"], [4, "ftypM4V "]], extensions: %w( mp4 m4v ) + +Marcel::MimeType.extend "font/ttf", magic: [[0, "\x00\x01\x00\x00"]], extensions: %w( ttf ttc ) +Marcel::MimeType.extend "font/otf", magic: [[0, "OTTO"]], extensions: %w( otf ), parents: "font/ttf" +Marcel::MimeType.extend "application/vnd.adobe.flash.movie", magic: [[0, "FWS"], [0, "CWS"]], extensions: %w( swf ) +Marcel::MimeType.extend "application/sql", extensions: %w( sql ) +Marcel::MimeType.extend "text/vcard", magic: [[0, "BEGIN:VCARD"]], extensions: %w( vcf ), parents: "text/plain" diff -Nru ruby-marcel-0.3.2/lib/marcel/mime_type.rb ruby-marcel-1.0.1+dfsg/lib/marcel/mime_type.rb --- ruby-marcel-0.3.2/lib/marcel/mime_type.rb 2018-05-02 13:02:52.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/lib/marcel/mime_type.rb 2021-04-02 18:30:30.000000000 +0530 @@ -1,97 +1,98 @@ -class Marcel::MimeType - BINARY = "application/octet-stream" +module Marcel + class MimeType + BINARY = "application/octet-stream" - class << self - def extend(type, extensions: [], parents: [], magic: nil) - existing = MimeMagic::TYPES[type] || [[], [], ""] - - extensions = (Array(extensions) + existing[0]).uniq - parents = (Array(parents) + existing[1]).uniq - comment = existing[2] + class << self + def extend(type, extensions: [], parents: [], magic: nil) + existing = Marcel::TYPES[type] || [[], [], ""] - MimeMagic.add(type, extensions: extensions, magic: magic, parents: parents, comment: comment) - end + extensions = (Array(extensions) + existing[0]).uniq + parents = (Array(parents) + existing[1]).uniq + comment = existing[2] - def for(pathname_or_io = nil, name: nil, extension: nil, declared_type: nil) - type_from_data = for_data(pathname_or_io) - fallback_type = for_declared_type(declared_type) || for_name(name) || for_extension(extension) || BINARY - - if type_from_data - most_specific_type type_from_data, fallback_type - else - fallback_type + Magic.add(type, extensions: extensions, magic: magic, parents: parents, comment: comment) end - end - private - def for_data(pathname_or_io) - if pathname_or_io - with_io(pathname_or_io) do |io| - if magic = MimeMagic.by_magic(io) - magic.type.downcase + def for(pathname_or_io = nil, name: nil, extension: nil, declared_type: nil) + type_from_data = for_data(pathname_or_io) + fallback_type = for_declared_type(declared_type) || for_name(name) || for_extension(extension) || BINARY + + if type_from_data + most_specific_type type_from_data, fallback_type + else + fallback_type + end + end + + private + def for_data(pathname_or_io) + if pathname_or_io + with_io(pathname_or_io) do |io| + if magic = Marcel::Magic.by_magic(io) + magic.type.downcase + end end end end - end - def for_name(name) - if name - if magic = MimeMagic.by_path(name) - magic.type.downcase + def for_name(name) + if name + if magic = Marcel::Magic.by_path(name) + magic.type.downcase + end end end - end - def for_extension(extension) - if extension - if magic = MimeMagic.by_extension(extension) - magic.type.downcase + def for_extension(extension) + if extension + if magic = Marcel::Magic.by_extension(extension) + magic.type.downcase + end end end - end - def for_declared_type(declared_type) - type = parse_media_type(declared_type) + def for_declared_type(declared_type) + type = parse_media_type(declared_type) - if type != BINARY && !type.nil? - type.downcase + if type != BINARY && !type.nil? + type.downcase + end end - end - def with_io(pathname_or_io, &block) - case pathname_or_io - when Pathname - pathname_or_io.open &block - else - yield pathname_or_io + def with_io(pathname_or_io, &block) + if defined?(Pathname) && pathname_or_io.is_a?(Pathname) + pathname_or_io.open(&block) + else + yield pathname_or_io + end end - end - def parse_media_type(content_type) - if content_type - result = content_type.downcase.split(/[;,\s]/, 2).first - result if result && result.index("/") + def parse_media_type(content_type) + if content_type + result = content_type.downcase.split(/[;,\s]/, 2).first + result if result && result.index("/") + end end - end - # For some document types (notably Microsoft Office) we recognise the main content - # type with magic, but not the specific subclass. In this situation, if we can get a more - # specific class using either the name or declared_type, we should use that in preference - def most_specific_type(from_magic_type, fallback_type) - if (root_types(from_magic_type) & root_types(fallback_type)).any? - fallback_type - else - from_magic_type + # For some document types (notably Microsoft Office) we recognise the main content + # type with magic, but not the specific subclass. In this situation, if we can get a more + # specific class using either the name or declared_type, we should use that in preference + def most_specific_type(from_magic_type, fallback_type) + if (root_types(from_magic_type) & root_types(fallback_type)).any? + fallback_type + else + from_magic_type + end end - end - def root_types(type) - if MimeMagic::TYPES[type].nil? || MimeMagic::TYPES[type][1].empty? - [ type ] - else - MimeMagic::TYPES[type][1].map {|t| root_types t }.flatten + def root_types(type) + if TYPES[type].nil? || TYPES[type][1].empty? + [ type ] + else + TYPES[type][1].map {|t| root_types t }.flatten + end end - end + end end end diff -Nru ruby-marcel-0.3.2/lib/marcel/version.rb ruby-marcel-1.0.1+dfsg/lib/marcel/version.rb --- ruby-marcel-0.3.2/lib/marcel/version.rb 2018-05-02 13:02:52.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/lib/marcel/version.rb 2021-04-02 18:30:30.000000000 +0530 @@ -1,3 +1,3 @@ module Marcel - VERSION = "0.3.2" + VERSION = "1.0.1" end diff -Nru ruby-marcel-0.3.2/lib/marcel.rb ruby-marcel-1.0.1+dfsg/lib/marcel.rb --- ruby-marcel-0.3.2/lib/marcel.rb 2018-05-02 13:02:52.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/lib/marcel.rb 2021-04-02 18:30:30.000000000 +0530 @@ -1,4 +1,5 @@ module Marcel - autoload :VERSION, 'marcel/version' - autoload :MimeType, 'marcel/mime_type' + require "marcel/version" + require "marcel/magic" + require "marcel/mime_type" end diff -Nru ruby-marcel-0.3.2/marcel.gemspec ruby-marcel-1.0.1+dfsg/marcel.gemspec --- ruby-marcel-0.3.2/marcel.gemspec 2018-05-02 13:02:52.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/marcel.gemspec 2021-04-02 18:30:30.000000000 +0530 @@ -9,20 +9,20 @@ spec.authors = ['Tom Ward'] spec.email = ['tom@basecamp.com'] spec.summary = %q{Simple mime type detection using magic numbers, filenames, and extensions} - spec.homepage = 'https://github.com/basecamp/marcel' - spec.license = 'MIT' + spec.homepage = 'https://github.com/rails/marcel' + spec.licenses = %w[ MIT Apache-2.0 ] - spec.files = `git ls-files -z`.split("\x0") + spec.files = Dir['lib/**/*', 'MIT-LICENSE', 'APACHE-LICENSE' 'README.md'] spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] spec.required_ruby_version = '>= 2.2' - spec.add_dependency 'mimemagic', '~> 0.3.2' - - spec.add_development_dependency 'minitest' - spec.add_development_dependency 'bundler', '~> 1.7' - spec.add_development_dependency 'rake', '~> 10.0' - spec.add_development_dependency 'rack', '~> 2.0.1' + spec.add_development_dependency 'minitest', '~> 5.11' + spec.add_development_dependency 'bundler', '>= 1.7' + spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rack', '~> 2.0' + spec.add_development_dependency 'nokogiri', '>= 1.9.1' + spec.add_development_dependency 'byebug', '~> 10.0.2' end diff -Nru ruby-marcel-0.3.2/Rakefile ruby-marcel-1.0.1+dfsg/Rakefile --- ruby-marcel-0.3.2/Rakefile 2018-05-02 13:02:52.000000000 +0530 +++ ruby-marcel-1.0.1+dfsg/Rakefile 2021-04-02 18:30:30.000000000 +0530 @@ -31,3 +31,9 @@ end end end + +desc "Generate data tables" +task tables: "lib/marcel/tables.rb" +file "lib/marcel/tables.rb" => %w[ data/tika.xml data/custom.xml ] do |target| + exec "script/generate_tables.rb", *target.prerequisites, out: target.name +end