Exemplo n.º 1
0
func otaruSetattr(fs *otaru.FileSystem, id inodedb.ID, req *bfuse.SetattrRequest) error {
	var valid otaru.ValidAttrFields
	var a otaru.Attr

	if req.Valid.Uid() {
		valid |= otaru.UidValid
		a.Uid = req.Uid
	}
	if req.Valid.Gid() {
		valid |= otaru.GidValid
		a.Gid = req.Gid
	}
	if req.Valid.Mode() {
		valid |= otaru.PermModeValid
		a.PermMode = uint16(req.Mode & os.ModePerm)
	}
	if req.Valid.Atime() {
		// otaru fs doesn't keep atime. set mtime instead.
		valid |= otaru.ModifiedTValid
		a.ModifiedT = req.Atime
	}
	if req.Valid.Mtime() {
		valid |= otaru.ModifiedTValid
		a.ModifiedT = req.Mtime
	}

	if valid != 0 {
		if err := fs.SetAttr(id, a, valid); err != nil {
			return err
		}
	}

	return nil
}
Exemplo n.º 2
0
func ServeFUSE(bucketName string, mountpoint string, ofs *otaru.FileSystem, ready chan<- bool) error {
	fsName := fmt.Sprintf("otaru+gs://%s", bucketName)
	volName := fmt.Sprintf("Otaru %s", bucketName)

	c, err := bfuse.Mount(
		mountpoint,
		bfuse.FSName(fsName),
		bfuse.Subtype("otarufs"),
		bfuse.VolumeName(volName),
	)
	if err != nil {
		return fmt.Errorf("bfuse.Mount failed: %v", err)
	}
	defer c.Close()

	serveC := make(chan error)
	go func() {
		if err := bfs.Serve(c, FileSystem{ofs}); err != nil {
			serveC <- err
			close(serveC)
			return
		}
		close(serveC)
	}()

	// check if the mount process has an error to report
	<-c.Ready
	if err := c.MountError; err != nil {
		return err
	}

	logger.Infof(mylog, "Mountpoint \"%s\" should be ready now!", mountpoint)
	if ready != nil {
		close(ready)
	}

	if err := <-serveC; err != nil {
		return nil
	}
	if err := ofs.Sync(); err != nil {
		return fmt.Errorf("Failed to Sync fs: %v", err)
	}
	return nil
}