2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

Fix invalid type in newly created packs

This commit is contained in:
Alexander Neumann 2016-08-04 18:40:31 +02:00
parent cff6fea32a
commit 3cca831b2e

View File

@ -119,7 +119,7 @@ var entrySize = uint(binary.Size(BlobType(0)) + binary.Size(uint32(0)) + backend
// headerEntry is used with encoding/binary to read and write header entries
type headerEntry struct {
Type BlobType
Type uint8
Length uint32
ID [backend.IDSize]byte
}
@ -177,11 +177,19 @@ func (p *Packer) Finalize() (uint, error) {
func (p *Packer) writeHeader(wr io.Writer) (bytesWritten uint, err error) {
for _, b := range p.blobs {
entry := headerEntry{
Type: b.Type,
Length: uint32(b.Length),
ID: b.ID,
}
switch b.Type {
case Data:
entry.Type = 0
case Tree:
entry.Type = 1
default:
return 0, fmt.Errorf("invalid blob type %v", b.Type)
}
err := binary.Write(wr, binary.LittleEndian, entry)
if err != nil {
return bytesWritten, err
@ -277,12 +285,22 @@ func NewUnpacker(k *crypto.Key, rd io.ReadSeeker) (*Unpacker, error) {
return nil, err
}
entries = append(entries, Blob{
Type: e.Type,
entry := Blob{
Length: uint(e.Length),
ID: e.ID,
Offset: pos,
})
}
switch e.Type {
case 0:
entry.Type = Data
case 1:
entry.Type = Tree
default:
return nil, fmt.Errorf("invalid type %d", e.Type)
}
entries = append(entries, entry)
pos += uint(e.Length)
}