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
70 manifest_text.split("\n").each do |stream|
71 toks = stream.split(" ")
73 stream = toks[0].gsub /\\(\\|[0-7]{3})/ do |escape_sequence|
80 toks[1..-1].each do |tok|
81 if (re = tok.match /^[0-9a-f]{32}/)
83 tok.split('+')[1..-1].each do |hint|
84 if !blocksize and hint.match /^\d+$/
87 if (re = hint.match /^GS(\d+)$/)
88 blocksize = re[1].to_i
91 @data_size = false if !blocksize
92 @data_size += blocksize if @data_size
94 if (re = tok.match /^(\d+):(\d+):(\S+)$/)
95 filename = re[3].gsub /\\(\\|[0-7]{3})/ do |escape_sequence|
101 @files << [stream, filename, re[2].to_i]
108 def self.normalize_uuid uuid
111 uuid.split('+').each do |token|
112 if token.match /^[0-9a-f]{32,}$/
113 raise "uuid #{uuid} has multiple hash parts" if hash_part
115 elsif token.match /^\d+$/
116 raise "uuid #{uuid} has multiple size parts" if size_part
120 raise "uuid #{uuid} has no hash part" if !hash_part
121 [hash_part, size_part].compact.join '+'