1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 08:16:36 +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 // headerEntry is used with encoding/binary to read and write header entries
type headerEntry struct { type headerEntry struct {
Type BlobType Type uint8
Length uint32 Length uint32
ID [backend.IDSize]byte 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) { func (p *Packer) writeHeader(wr io.Writer) (bytesWritten uint, err error) {
for _, b := range p.blobs { for _, b := range p.blobs {
entry := headerEntry{ entry := headerEntry{
Type: b.Type,
Length: uint32(b.Length), Length: uint32(b.Length),
ID: b.ID, 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) err := binary.Write(wr, binary.LittleEndian, entry)
if err != nil { if err != nil {
return bytesWritten, err return bytesWritten, err
@ -277,12 +285,22 @@ func NewUnpacker(k *crypto.Key, rd io.ReadSeeker) (*Unpacker, error) {
return nil, err return nil, err
} }
entries = append(entries, Blob{ entry := Blob{
Type: e.Type,
Length: uint(e.Length), Length: uint(e.Length),
ID: e.ID, ID: e.ID,
Offset: pos, 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) pos += uint(e.Length)
} }