Commit 447f5603 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use metadata stored in artifacats metadata file

parent e3ef0ac8
......@@ -18,8 +18,8 @@ class Projects::ArtifactsController < Projects::ApplicationController
return render_404 unless build.artifacts?
current_path = params[:path] ? "./#{params[:path]}/" : './'
artifacts_metadata = build.artifacts_metadata_for(current_path)
@path = Gitlab::StringPath.new(current_path, artifacts_metadata)
metadata = build.artifacts_metadata_for_path(current_path)
@path = Gitlab::StringPath.new(current_path, metadata)
end
private
......
......@@ -349,8 +349,23 @@ module Ci
artifacts? && artifacts_file.path.end_with?('zip') && artifacts_metadata.exists?
end
def artifacts_metadata_for(path)
{}
def artifacts_metadata_for_path(path)
return {} unless artifacts_metadata.exists?
metadata = []
meta_path = path.sub(/^\.\//, '')
File.open(artifacts_metadata.path) do |file|
gzip = Zlib::GzipReader.new(file)
gzip.each_line do |line|
if line =~ %r{^#{meta_path}[^/]+/?\s}
path, meta = line.split(' ')
metadata << path
end
end
gzip.close
end
metadata
end
private
......
......@@ -5,7 +5,7 @@ module Gitlab
# This is IO-operations safe class, that does similar job to
# Ruby's Pathname but without the risk of accessing filesystem.
#
# TODO: better support for '../' and './'
# TODO, better support for '../' and './'
#
class StringPath
attr_reader :path, :universe
......
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