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,omitempty"`
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 DeleteAt *time.Time `json:"delete_at,omitempty"`
31 IsTrashed bool `json:"is_trashed,omitempty"`
34 func (c Collection) resourceName() string {
38 // SizedDigests returns the hash+size part of each data block
39 // referenced by the collection.
40 func (c *Collection) SizedDigests() ([]SizedDigest, error) {
41 manifestText := c.ManifestText
42 if manifestText == "" {
43 manifestText = c.UnsignedManifestText
45 if manifestText == "" && c.PortableDataHash != "d41d8cd98f00b204e9800998ecf8427e+0" {
46 // TODO: Check more subtle forms of corruption, too
47 return nil, fmt.Errorf("manifest is missing")
50 scanner := bufio.NewScanner(strings.NewReader(manifestText))
51 scanner.Buffer(make([]byte, 1048576), len(manifestText))
53 line := scanner.Text()
54 tokens := strings.Split(line, " ")
56 return nil, fmt.Errorf("Invalid stream (<3 tokens): %q", line)
58 for _, token := range tokens[1:] {
59 if !blockdigest.LocatorPattern.MatchString(token) {
60 // FIXME: ensure it's a file token
63 // FIXME: shouldn't assume 32 char hash
64 if i := strings.IndexRune(token[33:], '+'); i >= 0 {
67 sds = append(sds, SizedDigest(token))
70 return sds, scanner.Err()
73 // CollectionList is an arvados#collectionList resource.
74 type CollectionList struct {
75 Items []Collection `json:"items"`
76 ItemsAvailable int `json:"items_available"`
77 Offset int `json:"offset"`
78 Limit int `json:"limit"`