X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/086c972bae004544cb43d9ea15388d486d3cd1ed..97d0e12a78e9245c8ed29c070ffe0399e5cd6cb4:/sdk/go/arvados/collection.go diff --git a/sdk/go/arvados/collection.go b/sdk/go/arvados/collection.go index e8b0f9cc98..cec20279d1 100644 --- a/sdk/go/arvados/collection.go +++ b/sdk/go/arvados/collection.go @@ -6,11 +6,13 @@ package arvados import ( "bufio" + "crypto/md5" "fmt" + "regexp" "strings" "time" - "git.curoverse.com/arvados.git/sdk/go/blockdigest" + "git.arvados.org/arvados.git/sdk/go/blockdigest" ) // Collection is an arvados#collection resource. @@ -32,10 +34,17 @@ type Collection struct { ReplicationDesired *int `json:"replication_desired"` StorageClassesDesired []string `json:"storage_classes_desired"` StorageClassesConfirmed []string `json:"storage_classes_confirmed"` - StorageClassesConfirmedAt time.Time `json:"storage_classes_confirmed_at"` + StorageClassesConfirmedAt *time.Time `json:"storage_classes_confirmed_at"` DeleteAt *time.Time `json:"delete_at"` IsTrashed bool `json:"is_trashed"` Properties map[string]interface{} `json:"properties"` + WritableBy []string `json:"writable_by,omitempty"` + FileCount int `json:"file_count"` + FileSizeTotal int64 `json:"file_size_total"` + Version int `json:"version"` + PreserveVersion bool `json:"preserve_version"` + CurrentVersionUUID string `json:"current_version_uuid"` + Description string `json:"description"` } func (c Collection) resourceName() string { @@ -44,6 +53,8 @@ func (c Collection) resourceName() string { // SizedDigests returns the hash+size part of each data block // referenced by the collection. +// +// Zero-length blocks are not included. func (c *Collection) SizedDigests() ([]SizedDigest, error) { manifestText := c.ManifestText if manifestText == "" { @@ -67,6 +78,10 @@ func (c *Collection) SizedDigests() ([]SizedDigest, error) { // FIXME: ensure it's a file token break } + if strings.HasPrefix(token, "d41d8cd98f00b204e9800998ecf8427e+0") { + // Exclude "empty block" placeholder + continue + } // FIXME: shouldn't assume 32 char hash if i := strings.IndexRune(token[33:], '+'); i >= 0 { token = token[:33+i] @@ -83,3 +98,28 @@ type CollectionList struct { Offset int `json:"offset"` Limit int `json:"limit"` } + +var ( + blkRe = regexp.MustCompile(`^ [0-9a-f]{32}\+\d+`) + tokRe = regexp.MustCompile(` ?[^ ]*`) +) + +// PortableDataHash computes the portable data hash of the given +// manifest. +func PortableDataHash(mt string) string { + h := md5.New() + size := 0 + _ = tokRe.ReplaceAllFunc([]byte(mt), func(tok []byte) []byte { + if m := blkRe.Find(tok); m != nil { + // write hash+size, ignore remaining block hints + tok = m + } + n, err := h.Write(tok) + if err != nil { + panic(err) + } + size += n + return nil + }) + return fmt.Sprintf("%x+%d", h.Sum(nil), size) +}