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