diff --git a/pkg/client/client.go b/pkg/client/client.go index 10217c81a..52c404a92 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -121,19 +121,20 @@ func NewFromShareRoot(shareBlobURL string) (c *Client, target *blobref.BlobRef, return nil, nil, fmt.Errorf("Error fetching %s: %v", shareBlobURL, err) } defer res.Body.Close() - ss, err := schema.ParseSuperset(res.Body) + blob, err := schema.BlobFromReader(blobref.Parse(root), res.Body) if err != nil { return nil, nil, fmt.Errorf("Error parsing JSON from %s: %v", shareBlobURL, err) } - if ss.AuthType != "haveref" { - return nil, nil, fmt.Errorf("Unknown share authType of %q", ss.AuthType) + if blob.ShareAuthType() != "haveref" { + return nil, nil, fmt.Errorf("Unknown share authType of %q", blob.ShareAuthType()) } - if ss.Target == nil { + target = blob.ShareTarget() + if target == nil { return nil, nil, fmt.Errorf("No target.") } - c.via[ss.Target.String()] = root + c.via[target.String()] = root // TODO(bradfitz): send via in requests, populate via as we fetch more things - return c, ss.Target, nil + return c, target, nil } // SetHTTPClient sets the Camlistore client's HTTP client. diff --git a/pkg/schema/blob.go b/pkg/schema/blob.go index 30392107f..0b5213cbd 100644 --- a/pkg/schema/blob.go +++ b/pkg/schema/blob.go @@ -124,6 +124,20 @@ func (b *Blob) StaticSetMembers() []*blobref.BlobRef { return s } +func (b *Blob) ShareAuthType() string { + if b.Type() != "share" { + return "" + } + return b.ss.AuthType +} + +func (b *Blob) ShareTarget() *blobref.BlobRef { + if b.Type() != "share" { + return nil + } + return b.ss.Target +} + // ModTime returns the "unixMtime" field, or the zero time. func (b *Blob) ModTime() time.Time { return b.ss.ModTime() }