diff --git a/src/restic/pack/pack.go b/src/restic/pack/pack.go index 2422e6533..815f9ddb8 100644 --- a/src/restic/pack/pack.go +++ b/src/restic/pack/pack.go @@ -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) }