From 8884e56d42c9cfd4ac20e9084597f4375b331d33 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 13 Apr 2025 20:24:38 +0100 Subject: [PATCH] Use pre-computed content type in trace#xml_file --- app/models/trace.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models/trace.rb b/app/models/trace.rb index 9768c0538..2147d0475 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -167,13 +167,12 @@ class Trace < ApplicationRecord end def xml_file - file.open do |tracefile| - filetype = Open3.capture2("/usr/bin/file", "-Lbz", tracefile.path).first.chomp - gzipped = filetype.include?("gzip compressed") - bzipped = filetype.include?("bzip2 compressed") - zipped = filetype.include?("Zip archive") - tarred = filetype.include?("tar archive") + gzipped = file.content_type.end_with?("gzip") + bzipped = file.content_type.end_with?("bzip2") + zipped = file.content_type.start_with?("application/zip") + tarred = file.content_type.start_with?("application/x-tar") + file.open do |tracefile| if gzipped || bzipped || zipped || tarred file = Tempfile.new("trace.#{id}") -- 2.39.5