From 044194b74617731ed8b471f7d609eff08596e8cd Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 29 Oct 2012 00:10:31 +0100 Subject: [PATCH] schema: document PopulateParts, add a missing error check Change-Id: Ic9d65fe3e56c4233f481254c6f730a8b382fb4ba --- pkg/schema/schema.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 1d71e09fb..dd6657f9a 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -520,6 +520,10 @@ func NewCommonFileMap(fileName string, fi os.FileInfo) Map { return m } +// PopulateParts populates the "parts" field of m with the provided +// parts. The sum of the sizes of parts must match the provided size +// or an error is returned. Also, each BytesPart may only contain either +// a BytesPart or a BlobRef, but not both. func PopulateParts(m Map, size int64, parts []BytesPart) error { sumSize := int64(0) mparts := make([]Map, len(parts)) @@ -528,11 +532,13 @@ func PopulateParts(m Map, size int64, parts []BytesPart) error { mparts[idx] = mpart switch { case part.BlobRef != nil && part.BytesRef != nil: - return errors.New("schema: part contains both blobRef and bytesRef") + return errors.New("schema: part contains both BlobRef and BytesRef") case part.BlobRef != nil: mpart["blobRef"] = part.BlobRef.String() case part.BytesRef != nil: mpart["bytesRef"] = part.BytesRef.String() + default: + return errors.New("schema: part must contain either a BlobRef or BytesRef") } mpart["size"] = part.Size sumSize += int64(part.Size)