1 class Collection < ArvadosModel
4 include CommonApiTemplate
6 api_accessible :user, extend: :common do |t|
11 api_accessible :with_data, extend: :user do |t|
16 if redundancy_confirmed_as.nil?
18 elsif redundancy_confirmed_as < redundancy
21 if redundancy_confirmed_at.nil?
23 elsif Time.now - redundancy_confirmed_at < 7.days
32 if self.manifest_text.nil? and self.uuid.nil?
34 elsif self.manifest_text and self.uuid
35 self.uuid.gsub! /\+.*/, ''
36 if self.uuid == Digest::MD5.hexdigest(self.manifest_text)
37 self.uuid.gsub! /$/, '+' + self.manifest_text.length.to_s
40 errors.add :uuid, 'does not match checksum of manifest_text'
43 elsif self.manifest_text
44 errors.add :uuid, 'not supplied (must match checksum of manifest_text)'
47 errors.add :manifest_text, 'not supplied'
53 inspect_manifest_text if @data_size.nil? or manifest_text_changed?
58 inspect_manifest_text if @files.nil? or manifest_text_changed?
62 def inspect_manifest_text
69 #normalized_manifest = ""
70 #IO.popen(['arv-normalize'], 'w+b') do |io|
71 # io.write manifest_text
73 # while buf = io.read(2**20)
74 # normalized_manifest += buf
81 manifest_text.split("\n").each do |stream|
82 toks = stream.split(" ")
84 stream = toks[0].gsub /\\(\\|[0-7]{3})/ do |escape_sequence|
91 toks[1..-1].each do |tok|
92 if (re = tok.match /^[0-9a-f]{32}/)
94 tok.split('+')[1..-1].each do |hint|
95 if !blocksize and hint.match /^\d+$/
98 if (re = hint.match /^GS(\d+)$/)
99 blocksize = re[1].to_i
102 @data_size = false if !blocksize
103 @data_size += blocksize if @data_size
105 if (re = tok.match /^(\d+):(\d+):(\S+)$/)
106 filename = re[3].gsub /\\(\\|[0-7]{3})/ do |escape_sequence|
112 fn = stream + '/' + filename
126 re = k.match(/^(.+)\/(.+)/)
127 @files << [re[1], re[2], v]
131 def self.uuid_like_pattern
132 "________________________________+%"
135 def self.normalize_uuid uuid
138 uuid.split('+').each do |token|
139 if token.match /^[0-9a-f]{32,}$/
140 raise "uuid #{uuid} has multiple hash parts" if hash_part
142 elsif token.match /^\d+$/
143 raise "uuid #{uuid} has multiple size parts" if size_part
147 raise "uuid #{uuid} has no hash part" if !hash_part
148 [hash_part, size_part].compact.join '+'