3 class Collection < ArvadosBase
4 MD5_EMPTY = 'd41d8cd98f00b204e9800998ecf8427e'
7 if Collection.is_empty_blob_locator? self.uuid
14 # Return true if the given string is the locator of a zero-length blob
15 def self.is_empty_blob_locator? locator
16 !!locator.to_s.match("^#{MD5_EMPTY}(\\+.*)?\$")
19 def self.goes_in_projects?
24 if @manifest.nil? or manifest_text_changed?
25 @manifest = Keep::Manifest.new(manifest_text || "")
31 # This method provides backwards compatibility for code that relied on
32 # the old files field in API results. New code should use manifest
38 ApplicationController.helpers.human_readable_bytes_html(total_bytes) + " " + super
42 manifest.files.inject(0) { |sum, filespec| sum + filespec.last }
46 tree = manifest.files.group_by do |file_spec|
47 File.split(file_spec.first)
49 return [] if tree.empty?
50 # Fill in entries for empty directories.
51 tree.keys.map { |basedir, _| File.split(basedir) }.each do |splitdir|
52 until tree.include?(splitdir)
54 splitdir = File.split(splitdir.first)
57 dir_to_tree = lambda do |dirname|
58 # First list subdirectories, with their files inside.
59 subnodes = tree.keys.select { |bd, td| (bd == dirname) and (td != '.') }
60 .sort.flat_map do |parts|
61 [parts + [nil]] + dir_to_tree.call(File.join(parts))
63 # Then extend that list with files in this directory.
64 subnodes + tree[File.split(dirname)]
69 def editable_attributes
70 %w(name description manifest_text)
78 arvados_api_client.api "collections/#{self.uuid}/", "provenance"
82 arvados_api_client.api "collections/#{self.uuid}/", "used_by"
87 return self[:portable_data_hash]
93 def portable_data_hash
94 if self[:portable_data_hash].nil?
101 def friendly_link_name lookup=nil
102 if self.respond_to? :name
105 self.portable_data_hash
109 def textile_attributes