summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects/artifacts_controller.rb4
-rw-r--r--app/models/ci/build.rb19
-rw-r--r--lib/gitlab/string_path.rb2
3 files changed, 20 insertions, 5 deletions
diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb
index 8a1ff383134..3a112587f72 100644
--- a/app/controllers/projects/artifacts_controller.rb
+++ b/app/controllers/projects/artifacts_controller.rb
@@ -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
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 98f9e6911f2..2c389bbdf61 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -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
diff --git a/lib/gitlab/string_path.rb b/lib/gitlab/string_path.rb
index af80a502bf6..bfeb0f852f0 100644
--- a/lib/gitlab/string_path.rb
+++ b/lib/gitlab/string_path.rb
@@ -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