From 884e8a63ea31cf0dfeaee5a90568584461f9b3d2 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 29 May 2011 18:22:56 -0700 Subject: [PATCH] fix WriteFileFromReader bug when chunks already exist. --- lib/go/camli/schema/filewriter.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/go/camli/schema/filewriter.go b/lib/go/camli/schema/filewriter.go index 4969632b1..5e5e6006f 100644 --- a/lib/go/camli/schema/filewriter.go +++ b/lib/go/camli/schema/filewriter.go @@ -21,6 +21,7 @@ import ( "crypto" "fmt" "io" + "log" "os" "strings" @@ -28,6 +29,8 @@ import ( "camli/blobserver" ) +var _ = log.Printf + // WriteFileFromReader creates and uploads a "file" JSON schema // composed of chunks of r, also uploading the chunks. The returned // BlobRef is of the JSON file schema blob. @@ -58,22 +61,21 @@ func WriteFileFromReader(bs blobserver.Storage, filename string, r io.Reader) (* if err != nil { return nil, err } - if hasBlob { - continue + if !hasBlob { + sb, err := bs.ReceiveBlob(br, buf) + if err != nil { + return nil, err + } + if expect := (blobref.SizedBlobRef{br, n}); !expect.Equal(sb) { + return nil, fmt.Errorf("schema/filewriter: wrote %s bytes, got %s ack'd", expect, sb) + } } - sb, err := bs.ReceiveBlob(br, buf) - if err != nil { - return nil, err - } - if expect := (blobref.SizedBlobRef{br, n}); !expect.Equal(sb) { - return nil, fmt.Errorf("schema/filewriter: wrote %s bytes, got %s ack'd", expect, sb) - } size += n parts = append(parts, ContentPart{ BlobRefString: br.String(), BlobRef: br, - Size: uint64(sb.Size), + Size: uint64(n), Offset: uint64(offset), }) }