Work around Go http bug with zero length files.

This commit is contained in:
Brad Fitzpatrick 2011-05-10 19:29:20 -07:00
parent 0123826aec
commit 1e7ff7b46c
4 changed files with 20 additions and 6 deletions

View File

@ -17,12 +17,15 @@ limitations under the License.
package main
import (
"camli/blobref"
"camli/client"
"flag"
"fmt"
"log"
"io"
"os"
"strings"
"camli/blobref"
"camli/client"
)
// Things that can be uploaded. (at most one of these)
@ -121,7 +124,12 @@ func doPass(sc, dc *client.Client, passNum int) (retErr os.Error) {
for sb := range destNotHaveBlobs {
fmt.Printf("Destination needs blob: %s\n", sb)
blobReader, size, err := sc.FetchStreaming(sb.BlobRef)
var (
blobReader io.Reader
size int64
err os.Error
)
blobReader, size, err = sc.FetchStreaming(sb.BlobRef)
if err != nil {
errorCount++
log.Printf("Error fetching %s: %v", sb.BlobRef, err)
@ -133,6 +141,11 @@ func doPass(sc, dc *client.Client, passNum int) (retErr os.Error) {
sb.Size, sb.BlobRef, size)
continue
}
if size == 0 {
// Hack.
// TODO-GO: fix http?
blobReader = strings.NewReader("")
}
uh := &client.UploadHandle{BlobRef: sb.BlobRef, Size: size, Contents: blobReader}
pr, err := dc.Upload(uh)
if err != nil {

View File

@ -54,7 +54,7 @@ func handleMultiPartUpload(conn http.ResponseWriter, req *http.Request, blobRece
var errText string
addError := func(s string) {
log.Printf("Client error: %s", s)
log.Printf("handlers/upload: client error: %s", s)
if errText == "" {
errText = s
return

View File

@ -302,6 +302,7 @@ func (c *Client) Upload(h *UploadHandle) (*PutResult, os.Error) {
req.TransferEncoding = nil
resp, err = c.httpClient.Do(req)
if err != nil {
log.Printf("client/upload: http write error: %v", err)
return error("upload http error: %v", err)
}

View File

@ -96,7 +96,7 @@ func (mi *Indexer) ReceiveBlob(blobRef *blobref.BlobRef, source io.Reader) (rets
hash := blobRef.Hash()
var written int64
written, err = io.Copy(io.MultiWriter(hash, sniffer), source)
log.Printf("mysqlindexer: wrote %d; err %v", written, err)
log.Printf("mysqlindexer/receive: copied to hash/sniffer %d; err %v", written, err)
if err != nil {
return
}
@ -108,7 +108,7 @@ func (mi *Indexer) ReceiveBlob(blobRef *blobref.BlobRef, source io.Reader) (rets
sniffer.Parse()
mimeType := sniffer.MimeType()
log.Printf("Read %d bytes; type=%v; truncated=%v", written, sniffer.IsTruncated())
log.Printf("mysqlindexer/receive: Read %d bytes; type=%v; truncated=%v", written, sniffer.IsTruncated())
var client *mysql.Client
if client, err = mi.getConnection(); err != nil {