Commit be764a3a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Minor improvements in build arfifacts browser

Added also a `Gitlab::Ci::Build::Artifacts::Metadata::ParserError`
exception class.
parent 76e578fd
......@@ -6,6 +6,6 @@
%td
= number_to_human_size(file.metadata[:size], precision: 2)
%td
= link_to file_namespace_project_build_artifacts_path(path: file.path),
= link_to file_namespace_project_build_artifacts_path(@project.namespace, @project, @build, path: file.path),
class: 'btn btn-xs btn-default artifact-download' do
= icon('download')
......@@ -609,8 +609,8 @@ Rails.application.routes.draw do
resource :artifacts, only: [] do
get :download
get :browse, path: 'browse(/*path)', action: :browse, format: false
get :file, path: 'file/*path', action: :file, format: false
get :browse, path: 'browse(/*path)', format: false
get :file, path: 'file/*path', format: false
end
end
......
......@@ -6,6 +6,8 @@ module Gitlab
module Build
module Artifacts
class Metadata
class ParserError < StandardError; end
VERSION_PATTERN = /^[\w\s]+(\d+\.\d+\.\d+)/
INVALID_PATH_PATTERN = %r{(^\.?\.?/)|(/\.?\.?/)}
......@@ -24,8 +26,13 @@ module Gitlab
gzip do |gz|
read_string(gz) # version
errors = read_string(gz)
raise StandardError, 'Errors field not found!' unless errors
JSON.parse(errors)
raise ParserError, 'Errors field not found!' unless errors
begin
JSON.parse(errors)
rescue JSON::ParserError
raise ParserError, 'Invalid errors field!'
end
end
end
......@@ -56,7 +63,7 @@ module Gitlab
next unless path =~ match_pattern
next if path =~ INVALID_PATH_PATTERN
entries.store(path, JSON.parse(meta, symbolize_names: true))
entries[path] = JSON.parse(meta, symbolize_names: true)
rescue JSON::ParserError, Encoding::CompatibilityError
next
end
......@@ -70,11 +77,11 @@ module Gitlab
version_string = read_string(gz)
unless version_string
raise StandardError, 'Artifacts metadata file empty!'
raise ParserError, 'Artifacts metadata file empty!'
end
unless version_string =~ VERSION_PATTERN
raise StandardError, 'Invalid version!'
raise ParserError, 'Invalid version!'
end
version_string.chomp
......
......@@ -57,7 +57,7 @@ module Gitlab
return @children if @children
child_pattern = %r{^#{Regexp.escape(@path)}[^/]+/?$}
@children = select_entries { |entry| entry =~ child_pattern }
@children = select_entries { |path| path =~ child_pattern }
end
def directories(opts = {})
......@@ -110,7 +110,7 @@ module Gitlab
private
def select_entries
selected = @entries.select { |entry, _metadata| yield entry }
selected = @entries.select { |path, _metadata| yield path }
selected.map { |path, _metadata| self.class.new(path, @entries) }
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