summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-01-13 23:24:28 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-01-14 12:48:17 +0100
commit0d6e7b9d3d38e60e5a706956a853e7dc940e4574 (patch)
tree8a0305f73a14a1884f788690f3ca434f4717991b /lib
parentad2b0358e0facd5c65c4141ce54c2e55bab165e6 (diff)
downloadgitlab-ce-0d6e7b9d3d38e60e5a706956a853e7dc940e4574.tar.gz
Use Hash to store paths and entries metadata in artifacts browser
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ci/build/artifacts/metadata.rb11
-rw-r--r--lib/gitlab/ci/build/artifacts/metadata/entry.rb18
2 files changed, 11 insertions, 18 deletions
diff --git a/lib/gitlab/ci/build/artifacts/metadata.rb b/lib/gitlab/ci/build/artifacts/metadata.rb
index 94821c0eae0..25ecf27d4e6 100644
--- a/lib/gitlab/ci/build/artifacts/metadata.rb
+++ b/lib/gitlab/ci/build/artifacts/metadata.rb
@@ -37,14 +37,14 @@ module Gitlab
end
def to_entry
- entries, metadata = find_entries!
- Entry.new(@path, entries, metadata)
+ entries = find_entries!
+ Entry.new(@path, entries)
end
private
def match_entries(gz)
- paths, metadata = [], []
+ entries = {}
match_pattern = %r{^#{Regexp.escape(@path)}[^/]*/?$}
until gz.eof? do
@@ -56,14 +56,13 @@ module Gitlab
next unless path =~ match_pattern
next if path =~ INVALID_PATH_PATTERN
- paths.push(path)
- metadata.push(JSON.parse(meta, symbolize_names: true))
+ entries.store(path, JSON.parse(meta, symbolize_names: true))
rescue JSON::ParserError, Encoding::CompatibilityError
next
end
end
- [paths, metadata]
+ entries
end
def read_version
diff --git a/lib/gitlab/ci/build/artifacts/metadata/entry.rb b/lib/gitlab/ci/build/artifacts/metadata/entry.rb
index 12bb1bf0346..4dae02ce4f7 100644
--- a/lib/gitlab/ci/build/artifacts/metadata/entry.rb
+++ b/lib/gitlab/ci/build/artifacts/metadata/entry.rb
@@ -14,10 +14,9 @@ module Gitlab
attr_reader :path, :entries
attr_accessor :name
- def initialize(path, entries, metadata = [])
- @path = path.force_encoding('UTF-8')
+ def initialize(path, entries)
+ @path = path.dup.force_encoding('UTF-8')
@entries = entries
- @metadata = metadata
if path.include?("\0")
raise ArgumentError, 'Path contains zero byte character!'
@@ -42,7 +41,7 @@ module Gitlab
def parent
return nil unless has_parent?
- new_entry(@path.chomp(basename))
+ self.class.new(@path.chomp(basename), @entries)
end
def basename
@@ -77,8 +76,7 @@ module Gitlab
end
def metadata
- @index ||= @entries.index(@path)
- @metadata[@index] || {}
+ @entries[@path] || {}
end
def nodes
@@ -111,13 +109,9 @@ module Gitlab
private
- def new_entry(path)
- self.class.new(path, @entries, @metadata)
- end
-
def select_entries
- selected = @entries.select { |entry| yield entry }
- selected.map { |path| new_entry(path) }
+ selected = @entries.select { |entry, _metadata| yield entry }
+ selected.map { |path, _metadata| self.class.new(path, @entries) }
end
end
end