示例#1
0
func (m *Manifest) ToBlob(type_ string) (*blobs.Manifest, error) {
	var k cas.Key
	if err := k.UnmarshalBinary(m.Root); err != nil {
		return nil, err
	}
	manifest := &blobs.Manifest{
		Type:      type_,
		Root:      k,
		Size:      m.Size,
		ChunkSize: m.ChunkSize,
		Fanout:    m.Fanout,
	}
	return manifest, nil
}
示例#2
0
func TestKeyUnmarshalBinaryBadLong(t *testing.T) {
	KEY := strings.Repeat("borketyBorkBORK!", 4) + "x"
	buf := []byte(KEY)
	var k cas.Key
	err := k.UnmarshalBinary(buf)
	if err == nil {
		t.Fatalf("unmarshal should have failed: %v", k)
	}
	e, ok := err.(*cas.BadKeySizeError)
	if !ok {
		t.Fatalf("unmarshal error is of wrong type: %T: %v", err, err)
	}
	if g, w := string(e.Key), KEY; g != w {
		t.Errorf("BadKeySizeError Key is wrong: %x != %x", g, w)
	}
}
示例#3
0
func (d *listSnaps) Lookup(ctx context.Context, name string) (fs.Node, error) {
	var ref wire.SnapshotRef
	lookup := func(tx *db.Tx) error {
		bucket := d.fs.bucket(tx).SnapBucket()
		if bucket == nil {
			return errors.New("snapshot bucket missing")
		}
		buf := bucket.Get([]byte(name))
		if buf == nil {
			return fuse.ENOENT
		}
		if err := proto.Unmarshal(buf, &ref); err != nil {
			return fmt.Errorf("corrupt snapshot reference: %q: %v", name, err)
		}
		return nil
	}
	if err := d.fs.db.View(lookup); err != nil {
		return nil, err
	}

	var k cas.Key
	if err := k.UnmarshalBinary(ref.Key); err != nil {
		return nil, fmt.Errorf("corrupt snapshot reference: %q: %v", name, err)
	}

	chunk, err := d.fs.chunkStore.Get(k, "snap", 0)
	if err != nil {
		return nil, fmt.Errorf("cannot fetch snapshot: %v", err)
	}

	var snapshot wiresnap.Snapshot
	err = proto.Unmarshal(chunk.Buf, &snapshot)
	if err != nil {
		return nil, fmt.Errorf("corrupt snapshot: %v: %v", ref.Key, err)
	}

	n, err := snap.Open(d.fs.chunkStore, snapshot.Contents)
	if err != nil {
		return nil, fmt.Errorf("cannot serve snapshot: %v", err)
	}
	return n, nil
}