fix WriteFileFromReader bug when chunks already exist.

This commit is contained in:
Brad Fitzpatrick 2011-05-29 18:22:56 -07:00
parent 407bc3cf35
commit 884e8a63ea
1 changed files with 12 additions and 10 deletions

View File

@ -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),
})
}