schema: use better types in superset: blobref and Time3339

Change-Id: I7004220789e1048c1ebcc8703bf2948a733bae10
This commit is contained in:
Brad Fitzpatrick 2013-02-10 12:58:51 -08:00
parent 11e07730ca
commit 9efdf83d3e
3 changed files with 20 additions and 20 deletions

View File

@ -91,10 +91,10 @@ func (b *Blob) FileName() string {
func (b *Blob) ClaimDate() (time.Time, error) {
var ct time.Time
claimDate := b.ss.ClaimDate
if claimDate == "" {
if claimDate.IsZero() {
return ct, MissingFieldError("claimDate")
}
return time.Parse(time.RFC3339, claimDate)
return claimDate.Time(), nil
}
// ByteParts returns the "parts" field. The caller owns the returned
@ -120,7 +120,7 @@ func (b *Blob) Builder() *Builder {
// AsClaim returns a Claim if the receiver Blob has all the required fields.
func (b *Blob) AsClaim() (c Claim, ok bool) {
if blobref.Parse(b.ss.Signer) != nil && b.ss.Sig != "" && b.ss.ClaimType != "" && b.ss.ClaimDate != "" {
if b.ss.Signer != nil && b.ss.Sig != "" && b.ss.ClaimType != "" && !b.ss.ClaimDate.IsZero() {
return Claim{b}, true
}
return
@ -132,7 +132,7 @@ func (b *Blob) DirectoryEntries() *blobref.BlobRef {
if b.Type() != "directory" {
return nil
}
return blobref.Parse(b.ss.Entries)
return b.ss.Entries
}
func (b *Blob) StaticSetMembers() []*blobref.BlobRef {
@ -140,8 +140,8 @@ func (b *Blob) StaticSetMembers() []*blobref.BlobRef {
return nil
}
s := make([]*blobref.BlobRef, 0, len(b.ss.Members))
for _, refstr := range b.ss.Members {
if ref := blobref.Parse(refstr); ref != nil {
for _, ref := range b.ss.Members {
if ref != nil {
s = append(s, ref)
}
}
@ -174,7 +174,7 @@ type Claim struct {
func (c Claim) Blob() *Blob { return c.b }
// ClaimDate returns the blob's "claimDate" field.
func (c Claim) ClaimDateString() string { return c.b.ss.ClaimDate }
func (c Claim) ClaimDateString() string { return c.b.ss.ClaimDate.String() }
// ClaimType returns the blob's "claimType" field.
func (c Claim) ClaimType() string { return c.b.ss.ClaimType }
@ -188,7 +188,7 @@ func (c Claim) Value() string { return c.b.ss.Value }
// ModifiedPermanode returns the claim's "permaNode" field, if it's
// a claim that modifies a permanode. Otherwise nil is returned.
func (c Claim) ModifiedPermanode() *blobref.BlobRef {
return blobref.Parse(c.b.ss.Permanode)
return c.b.ss.Permanode
}
// A Builder builds a JSON blob.

View File

@ -86,7 +86,7 @@ func (dr *DirReader) StaticSet() ([]*blobref.BlobRef, error) {
if dr.staticSet != nil {
return dr.staticSet, nil
}
staticSetBlobref := blobref.Parse(dr.ss.Entries)
staticSetBlobref := dr.ss.Entries
if staticSetBlobref == nil {
return nil, fmt.Errorf("schema/filereader: Invalid blobref\n")
}
@ -101,8 +101,7 @@ func (dr *DirReader) StaticSet() ([]*blobref.BlobRef, error) {
if ss.Type != "static-set" {
return nil, fmt.Errorf("schema/filereader: expected \"static-set\" schema blob for %s, got %q", staticSetBlobref, ss.Type)
}
for _, s := range ss.Members {
member := blobref.Parse(s)
for _, member := range ss.Members {
if member == nil {
return nil, fmt.Errorf("schema/filereader: invalid (static-set member) blobref\n")
}

View File

@ -39,6 +39,7 @@ import (
"time"
"camlistore.org/pkg/blobref"
"camlistore.org/pkg/types"
"camlistore.org/third_party/github.com/camlistore/goexif/exif"
)
@ -202,15 +203,15 @@ type superset struct {
Version int `json:"camliVersion"`
Type string `json:"camliType"`
Signer string `json:"camliSigner"`
Sig string `json:"camliSig"`
Signer *blobref.BlobRef `json:"camliSigner"`
Sig string `json:"camliSig"`
ClaimType string `json:"claimType"`
ClaimDate string `json:"claimDate"`
ClaimType string `json:"claimType"`
ClaimDate types.Time3339 `json:"claimDate"`
Permanode string `json:"permaNode"`
Attribute string `json:"attribute"`
Value string `json:"value"`
Permanode *blobref.BlobRef `json:"permaNode"`
Attribute string `json:"attribute"`
Value string `json:"value"`
// FileName and FileNameBytes represent one of the two
// representations of file names in schema blobs. They should
@ -235,8 +236,8 @@ type superset struct {
// See doc/schema/bytes.txt and doc/schema/files/file.txt.
Parts []*BytesPart `json:"parts"`
Entries string `json:"entries"` // for directories, a blobref to a static-set
Members []string `json:"members"` // for static sets (for directory static-sets: blobrefs to child dirs/files)
Entries *blobref.BlobRef `json:"entries"` // for directories, a blobref to a static-set
Members []*blobref.BlobRef `json:"members"` // for static sets (for directory static-sets: blobrefs to child dirs/files)
// Target is a "share" blob's target (the thing being shared)
Target *blobref.BlobRef `json:"target"`