Merge branch '8784-dir-listings'
[arvados.git] / sdk / go / arvados / collection.go
index 9274238d2806c61a857414999a3b284ab7d2182b..61bcd7fe8f367f2ca3d3d48017213bbd5335d33e 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
 package arvados
 
 import (
@@ -6,7 +10,7 @@ import (
        "strings"
        "time"
 
-       "git.curoverse.com/arvados.git/sdk/go/manifest"
+       "git.curoverse.com/arvados.git/sdk/go/blockdigest"
 )
 
 // Collection is an arvados#collection resource.
@@ -14,6 +18,8 @@ type Collection struct {
        UUID                   string     `json:"uuid,omitempty"`
        TrashAt                *time.Time `json:"trash_at,omitempty"`
        ManifestText           string     `json:"manifest_text,omitempty"`
+       UnsignedManifestText   string     `json:"unsigned_manifest_text,omitempty"`
+       Name                   string     `json:"name,omitempty"`
        CreatedAt              *time.Time `json:"created_at,omitempty"`
        ModifiedAt             *time.Time `json:"modified_at,omitempty"`
        PortableDataHash       string     `json:"portable_data_hash,omitempty"`
@@ -27,13 +33,17 @@ type Collection struct {
 // SizedDigests returns the hash+size part of each data block
 // referenced by the collection.
 func (c *Collection) SizedDigests() ([]SizedDigest, error) {
-       if c.ManifestText == "" && c.PortableDataHash != "d41d8cd98f00b204e9800998ecf8427e+0" {
+       manifestText := c.ManifestText
+       if manifestText == "" {
+               manifestText = c.UnsignedManifestText
+       }
+       if manifestText == "" && c.PortableDataHash != "d41d8cd98f00b204e9800998ecf8427e+0" {
                // TODO: Check more subtle forms of corruption, too
                return nil, fmt.Errorf("manifest is missing")
        }
        var sds []SizedDigest
-       scanner := bufio.NewScanner(strings.NewReader(c.ManifestText))
-       scanner.Buffer(make([]byte, 1048576), len(c.ManifestText))
+       scanner := bufio.NewScanner(strings.NewReader(manifestText))
+       scanner.Buffer(make([]byte, 1048576), len(manifestText))
        for scanner.Scan() {
                line := scanner.Text()
                tokens := strings.Split(line, " ")
@@ -41,7 +51,7 @@ func (c *Collection) SizedDigests() ([]SizedDigest, error) {
                        return nil, fmt.Errorf("Invalid stream (<3 tokens): %q", line)
                }
                for _, token := range tokens[1:] {
-                       if !manifest.LocatorPattern.MatchString(token) {
+                       if !blockdigest.LocatorPattern.MatchString(token) {
                                // FIXME: ensure it's a file token
                                break
                        }