From 3b792c2892acbff2437f138784bb0eb6d907a59e Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 13 Apr 2025 20:26:01 +0100 Subject: [PATCH] Workaround bug in file 5.46 The 5.46 release of file has a bug that means when the -z switch is used on a zip file it tries and fails to decompress it so make sure to only use -z on things we know are compressed. https://bugs.astron.com/view.php?id=643 --- app/models/trace.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/models/trace.rb b/app/models/trace.rb index 2147d0475..749a8bfb9 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -279,13 +279,19 @@ class Trace < ApplicationRecord private def content_type(file) - case Open3.capture2("/usr/bin/file", "-Lbz", file).first.chomp - when /.*\btar archive\b.*\bgzip\b/ then "application/x-tar+gzip" - when /.*\btar archive\b.*\bbzip2\b/ then "application/x-tar+x-bzip2" - when /.*\btar archive\b/ then "application/x-tar" - when /.*\bZip archive\b/ then "application/zip" - when /.*\bXML\b.*\bgzip\b/ then "application/gzip" - when /.*\bXML\b.*\bbzip2\b/ then "application/x-bzip2" + file_type = Open3.capture2("/usr/bin/file", "-Lb", file).first.chomp + + case file_type + when /\bcompressed data,/ then file_type = Open3.capture2("/usr/bin/file", "-Lbz", file).first.chomp + end + + case file_type + when /\btar archive\b.*\bgzip\b/ then "application/x-tar+gzip" + when /\btar archive\b.*\bbzip2\b/ then "application/x-tar+x-bzip2" + when /\btar archive\b/ then "application/x-tar" + when /\bZip archive\b/ then "application/zip" + when /\bXML\b.*\bgzip\b/ then "application/gzip" + when /\bXML\b.*\bbzip2\b/ then "application/x-bzip2" else "application/gpx+xml" end end -- 2.39.5