Beispiel #1
0
func (ds *DiskStorage) blobDirectory(b blob.Ref) string {
	d := b.Digest()
	if len(d) < 4 {
		d = d + "____"
	}
	return filepath.Join(ds.root, b.HashName(), d[0:2], d[2:4])
}
Beispiel #2
0
func (s *Storage) Fetch(br blob.Ref) (rc io.ReadCloser, size uint32, err error) {
	if s.cache != nil {
		if rc, size, err = s.cache.Fetch(br); err == nil {
			return
		}
	}
	r, fi, err := s.cl.DownloadFileByName(s.b.Name, s.dirPrefix+br.String())
	if err, ok := err.(*b2.Error); ok && err.Status == 404 {
		return nil, 0, os.ErrNotExist
	}
	if err != nil {
		return nil, 0, err
	}

	if br.HashName() == "sha1" && fi.ContentSHA1 != br.Digest() {
		return nil, 0, errors.New("b2: remote ContentSHA1 mismatch")
	}

	if fi.ContentLength >= 1<<32 {
		r.Close()
		return nil, 0, errors.New("object larger than a uint32")
	}
	size = uint32(fi.ContentLength)
	if size > constants.MaxBlobSize {
		r.Close()
		return nil, size, errors.New("object too big")
	}
	return r, size, nil
}
Beispiel #3
0
func (ds *DiskStorage) blobDirectory(partition string, b blob.Ref) string {
	d := b.Digest()
	if len(d) < 6 {
		d = d + "______"
	}
	return filepath.Join(ds.PartitionRoot(partition), b.HashName(), d[0:3], d[3:6])
}
Beispiel #4
0
func (s *Storage) ReceiveBlob(br blob.Ref, source io.Reader) (blob.SizedRef, error) {
	var buf bytes.Buffer
	size, err := io.Copy(&buf, source)
	if err != nil {
		return blob.SizedRef{}, err
	}

	b := bytes.NewReader(buf.Bytes())
	fi, err := s.b.Upload(b, s.dirPrefix+br.String(), "")
	if err != nil {
		return blob.SizedRef{}, err
	}

	if int64(fi.ContentLength) != size {
		return blob.SizedRef{}, fmt.Errorf("b2: expected ContentLength %d, got %d", size, fi.ContentLength)
	}
	if br.HashName() == "sha1" && fi.ContentSHA1 != br.Digest() {
		return blob.SizedRef{}, fmt.Errorf("b2: expected ContentSHA1 %s, got %s", br.Digest(), fi.ContentSHA1)
	}

	if s.cache != nil {
		// NoHash because it's already verified if we read it without
		// errors from the source, and uploaded it without mismatch.
		blobserver.ReceiveNoHash(s.cache, br, &buf)
	}
	return blob.SizedRef{Ref: br, Size: uint32(size)}, nil
}
Beispiel #5
0
func blobFileBaseName(b blob.Ref) string {
	return fmt.Sprintf("%s-%s.dat", b.HashName(), b.Digest())
}