Esempio n. 1
0
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
}
Esempio n. 2
0
func (fs *FS) CreateFile(fpath string) (durablefs.File, error) {
	//println("durable fs make:", path.Join(fs.zroot, fpath))
	if err := zutil.CreateRecursive(fs.conn, path.Join(fs.zroot, fpath), zutil.PermitAll); err != nil {
		return nil, err
	}
	return fs.OpenFile(fpath)
}
Esempio n. 3
0
func makeDir(fs *FS, anchor string) (*Dir, error) {
	dir := &Dir{
		fs:     fs,
		anchor: anchor,
	}
	dir.watch = zutil.InstallWatch(fs.zookeeper, dir.zdir())
	// The semantics of AnchorFS pretend that all directories always exist,
	// which is not the case in Zookeeper. To make this work, we create the
	// directory on access.
	if err := zutil.CreateRecursive(dir.fs.zookeeper, dir.zdir(), zutil.PermitAll); err != nil {
		return nil, err
	}
	return dir, nil
}
Esempio n. 4
0
func New(z *zookeeper.Conn, root string) *FS {
	zutil.CreateRecursive(z, path.Join(root, "listener"), zutil.PermitAll)
	zutil.CreateRecursive(z, path.Join(root, "unresolved"), zutil.PermitAll)
	zutil.CreateRecursive(z, path.Join(root, "resolved"), zutil.PermitAll)
	return &FS{z: z, root: root}
}