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
39 ApplicationController.helpers.human_readable_bytes_html(total_bytes) + " " + super
41 super + " modified at " + modified_at.to_s
46 manifest.files.inject(0) { |sum, filespec| sum + filespec.last }
50 tree = manifest.files.group_by do |file_spec|
51 File.split(file_spec.first)
53 return [] if tree.empty?
54 # Fill in entries for empty directories.
55 tree.keys.map { |basedir, _| File.split(basedir) }.each do |splitdir|
56 until tree.include?(splitdir)
58 splitdir = File.split(splitdir.first)
61 dir_to_tree = lambda do |dirname|
62 # First list subdirectories, with their files inside.
63 subnodes = tree.keys.select { |bd, td| (bd == dirname) and (td != '.') }
64 .sort.flat_map do |parts|
65 [parts + [nil]] + dir_to_tree.call(File.join(parts))
67 # Then extend that list with files in this directory.
68 subnodes + tree[File.split(dirname)]
73 def editable_attributes
74 %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 friendly_link_name lookup=nil
94 name || portable_data_hash
97 def textile_attributes