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,omitempty"`
19 OwnerUUID string `json:"owner_uuid,omitempty"`
20 TrashAt *time.Time `json:"trash_at,omitempty"`
21 ManifestText string `json:"manifest_text"`
22 UnsignedManifestText string `json:"unsigned_manifest_text,omitempty"`
23 Name string `json:"name,omitempty"`
24 CreatedAt *time.Time `json:"created_at,omitempty"`
25 ModifiedAt *time.Time `json:"modified_at,omitempty"`
26 PortableDataHash string `json:"portable_data_hash,omitempty"`
27 ReplicationConfirmed *int `json:"replication_confirmed,omitempty"`
28 ReplicationConfirmedAt *time.Time `json:"replication_confirmed_at,omitempty"`
29 ReplicationDesired *int `json:"replication_desired,omitempty"`
30 StorageClassesDesired []string `json:"storage_classes_desired,omitempty"`
31 StorageClassesConfirmed []string `json:"storage_classes_confirmed,omitempty"`
32 StorageClassesConfirmedAt *time.Time `json:"storage_classes_confirmed_at,omitempty"`
33 DeleteAt *time.Time `json:"delete_at,omitempty"`
34 IsTrashed bool `json:"is_trashed,omitempty"`
37 func (c Collection) resourceName() string {
41 // SizedDigests returns the hash+size part of each data block
42 // referenced by the collection.
43 func (c *Collection) SizedDigests() ([]SizedDigest, error) {
44 manifestText := c.ManifestText
45 if manifestText == "" {
46 manifestText = c.UnsignedManifestText
48 if manifestText == "" && c.PortableDataHash != "d41d8cd98f00b204e9800998ecf8427e+0" {
49 // TODO: Check more subtle forms of corruption, too
50 return nil, fmt.Errorf("manifest is missing")
53 scanner := bufio.NewScanner(strings.NewReader(manifestText))
54 scanner.Buffer(make([]byte, 1048576), len(manifestText))
56 line := scanner.Text()
57 tokens := strings.Split(line, " ")
59 return nil, fmt.Errorf("Invalid stream (<3 tokens): %q", line)
61 for _, token := range tokens[1:] {
62 if !blockdigest.LocatorPattern.MatchString(token) {
63 // FIXME: ensure it's a file token
66 // FIXME: shouldn't assume 32 char hash
67 if i := strings.IndexRune(token[33:], '+'); i >= 0 {
70 sds = append(sds, SizedDigest(token))
73 return sds, scanner.Err()
76 // CollectionList is an arvados#collectionList resource.
77 type CollectionList struct {
78 Items []Collection `json:"items"`
79 ItemsAvailable int `json:"items_available"`
80 Offset int `json:"offset"`
81 Limit int `json:"limit"`