Пример #1
0
func NewOSStore(rootDir string, owner *types.Identity, capacity int64) (Storer, error) {
	var err error
	dataDir := filepath.Join(rootDir, "data")

	if owner == nil {
		return nil, errors.New("NewOSStore expected non-nil owner")
	}

	_, err = fs.EnsureDir(rootDir)
	if err != nil {
		return nil, err
	}
	_, err = fs.EnsureDir(dataDir)
	if err != nil {
		return nil, err
	}
	indexPath := filepath.Join(rootDir, "index.sqlite")
	index, err := NewIndex(indexPath)
	if err != nil {
		return nil, err
	}

	// set meta
	index.Set(MetaCapacity, strconv.FormatInt(capacity, 10))
	index.Set(MetaOwner, types.KeyToString(owner.PublicKey))

	return &OSStore{
		RootDir: rootDir,
		DataDir: dataDir,
		Index:   index,
	}, nil
}
Пример #2
0
func NewOSStorehouser(rootDir string) (Storehouser, error) {
	_, err := fs.EnsureDir(rootDir)
	if err != nil {
		return nil, err
	}
	return &OSStorehouser{rootDir}, nil
}