mirror of https://github.com/perkeep/perkeep.git
fix WriteFileFromReader bug when chunks already exist.
This commit is contained in:
parent
407bc3cf35
commit
884e8a63ea
|
@ -21,6 +21,7 @@ import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -28,6 +29,8 @@ import (
|
||||||
"camli/blobserver"
|
"camli/blobserver"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ = log.Printf
|
||||||
|
|
||||||
// WriteFileFromReader creates and uploads a "file" JSON schema
|
// WriteFileFromReader creates and uploads a "file" JSON schema
|
||||||
// composed of chunks of r, also uploading the chunks. The returned
|
// composed of chunks of r, also uploading the chunks. The returned
|
||||||
// BlobRef is of the JSON file schema blob.
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if hasBlob {
|
if !hasBlob {
|
||||||
continue
|
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
|
size += n
|
||||||
parts = append(parts, ContentPart{
|
parts = append(parts, ContentPart{
|
||||||
BlobRefString: br.String(),
|
BlobRefString: br.String(),
|
||||||
BlobRef: br,
|
BlobRef: br,
|
||||||
Size: uint64(sb.Size),
|
Size: uint64(n),
|
||||||
Offset: uint64(offset),
|
Offset: uint64(offset),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue