1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 "git.curoverse.com/arvados.git/sdk/go/blockdigest"
16 // Collection is an arvados#collection resource.
17 type Collection struct {
18 UUID string `json:"uuid"`
19 Etag string `json:"etag"`
20 OwnerUUID string `json:"owner_uuid"`
21 TrashAt *time.Time `json:"trash_at"`
22 ManifestText string `json:"manifest_text"`
23 UnsignedManifestText string `json:"unsigned_manifest_text"`
24 Name string `json:"name"`
25 CreatedAt *time.Time `json:"created_at"`
26 ModifiedAt *time.Time `json:"modified_at"`
27 PortableDataHash string `json:"portable_data_hash"`
28 ReplicationConfirmed *int `json:"replication_confirmed"`
29 ReplicationConfirmedAt *time.Time `json:"replication_confirmed_at"`
30 ReplicationDesired *int `json:"replication_desired"`
31 StorageClassesDesired []string `json:"storage_classes_desired"`
32 StorageClassesConfirmed []string `json:"storage_classes_confirmed"`
33 StorageClassesConfirmedAt *time.Time `json:"storage_classes_confirmed_at"`
34 DeleteAt *time.Time `json:"delete_at"`
35 IsTrashed bool `json:"is_trashed"`
36 Properties map[string]interface{} `json:"properties"`
39 func (c Collection) resourceName() string {
43 // SizedDigests returns the hash+size part of each data block
44 // referenced by the collection.
45 func (c *Collection) SizedDigests() ([]SizedDigest, error) {
46 manifestText := c.ManifestText
47 if manifestText == "" {
48 manifestText = c.UnsignedManifestText
50 if manifestText == "" && c.PortableDataHash != "d41d8cd98f00b204e9800998ecf8427e+0" {
51 // TODO: Check more subtle forms of corruption, too
52 return nil, fmt.Errorf("manifest is missing")
55 scanner := bufio.NewScanner(strings.NewReader(manifestText))
56 scanner.Buffer(make([]byte, 1048576), len(manifestText))
58 line := scanner.Text()
59 tokens := strings.Split(line, " ")
61 return nil, fmt.Errorf("Invalid stream (<3 tokens): %q", line)
63 for _, token := range tokens[1:] {
64 if !blockdigest.LocatorPattern.MatchString(token) {
65 // FIXME: ensure it's a file token
68 // FIXME: shouldn't assume 32 char hash
69 if i := strings.IndexRune(token[33:], '+'); i >= 0 {
72 sds = append(sds, SizedDigest(token))
75 return sds, scanner.Err()
78 type CollectionList struct {
79 Items []Collection `json:"items"`
80 ItemsAvailable int `json:"items_available"`
81 Offset int `json:"offset"`
82 Limit int `json:"limit"`