コード例 #1
0
ファイル: fs.go プロジェクト: johnvilsack/golang-stuff
func (fs *FS) CreateFile(anchor string, owner circuit.Addr) error {
	// Probably should save addr using durable-like techniques
	var w bytes.Buffer
	if err := gob.NewEncoder(&w).Encode(&ZFile{owner}); err != nil {
		panic(err)
	}

	parts, _, err := anchorfs.Sanitize(anchor)
	if err != nil {
		return err
	}
	_anchor := path.Join(append([]string{fs.root}, parts...)...)
	println(_anchor)
	if err = zutil.CreateRecursive(fs.zookeeper, _anchor, zutil.PermitAll); err != nil {
		return err
	}

	_, err = fs.zookeeper.Create(
		path.Join(_anchor, owner.WorkerID().String()),
		string(w.Bytes()),
		zookeeper.EPHEMERAL,
		zutil.PermitAll,
	)
	if err != nil {
		return err
	}

	fs.Lock()
	defer fs.Unlock()
	fs.created[anchor] = struct{}{}

	return nil
}
コード例 #2
0
ファイル: fs.go プロジェクト: johnvilsack/golang-stuff
func (fs *FS) OpenDir(anchor string) (anchorfs.Dir, error) {
	_, anchor, err := anchorfs.Sanitize(anchor)
	if err != nil {
		return nil, err
	}

	fs.Lock()
	defer fs.Unlock()

	// Directory open already?
	dir, present := fs.anchors[anchor]
	if present {
		return dir, nil
	}
	// No, make new instance
	if dir, err = makeDir(fs, anchor); err != nil {
		return nil, err
	}
	fs.anchors[anchor] = dir

	return dir, nil
}