1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'zlib'
require 'json'
module Gitlab
module Ci
module Build
module Artifacts
class Metadata
def initialize(file, path)
@file = file
@path = path.sub(/^\.\//, '')
@path << '/' unless path.end_with?('/')
end
def exists?
File.exists?(@file)
end
def match!
raise StandardError, 'Metadata file not found !' unless exists?
paths, metadata = [], []
each do |line|
next unless line =~ %r{^#{Regexp.escape(@path)}[^/\s]+/?\s}
path, meta = line.split(' ')
paths.push(path)
metadata.push(meta)
end
[paths, metadata.map { |meta| JSON.parse(meta) }]
end
def to_string_path
universe, metadata = match!
::Gitlab::StringPath.new(@path, universe, metadata)
end
private
def each
open do |file|
gzip = Zlib::GzipReader.new(file)
gzip.each_line { |line| yield line }
gzip.close
end
end
def open
File.open(@file) { |file| yield file }
end
end
end
end
end
end