Exemple #1
0
func New(path, fsName string) (*BlobStore, error) {
	if path == "" {
		path = filepath.Join(pathutil.VarDir(), "blobfs", "blobstore")
	}
	bs := &BlobStore{path: path, fs: fsName}
	if err := os.MkdirAll(filepath.Join(path, fsName), 0700); err != nil {
		return nil, err
	}

	return bs, nil
}
Exemple #2
0
func (bs *BlobStore) Stat(hash string) (bool, error) {
	f, err := os.Open(filepath.Join(pathutil.VarDir(), "blobfs", "blobstore", bs.fs, hash[0:2], hash))
	defer f.Close()
	switch {
	case err == nil:
		return true, nil
	case os.IsNotExist(err):
		return false, nil
	default:
		return false, err
	}
}
Exemple #3
0
func (bs *BlobStore) Get(hash string) ([]byte, error) {
	blob, err := ioutil.ReadFile(filepath.Join(pathutil.VarDir(), "blobfs", "blobstore", bs.fs, hash[0:2], hash))
	switch {
	case err == nil:
		return blob, nil
	case os.IsNotExist(err):
		return nil, ErrBlobNotFound
	default:
		return nil, err
	}

}
Exemple #4
0
func (bs *BlobStore) Remove(hash string) error {
	return os.Remove(filepath.Join(pathutil.VarDir(), "blobfs", "blobstore", bs.fs, hash[0:2], hash))
}
Exemple #5
0
func (bs *BlobStore) Put(hash string, data []byte) error {
	if err := os.MkdirAll(filepath.Join(pathutil.VarDir(), "blobfs", "blobstore", bs.fs, hash[0:2]), 0700); err != nil {
		return err
	}
	return ioutil.WriteFile(filepath.Join(pathutil.VarDir(), "blobfs", "blobstore", bs.fs, hash[0:2], hash), data, 0644)
}
Exemple #6
0
func (bs *BlobStore) Iter(walkFunc func(string, string, error) error) error {
	return filepath.Walk(filepath.Join(pathutil.VarDir(), "blobfs", "blobstore", bs.fs), bs.iter(walkFunc))
}