func (d *DriveFile) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
	d.Lock()
	defer d.Unlock()
	err := d.TmpFile.Sync()
	if err != nil {
		log.Println(err)
		return err
	}
	d.TmpFile.Close()
	d.TmpFile, err = os.Open(d.TmpFile.Name())
	if err != nil {
		log.Println(err)
	}
	errChan := make(chan error)
	fileChan := make(chan *drive.File)
	defer func() {
		close(errChan)
		close(fileChan)
	}()
	go func() {
		f, err := service.Files.Update(d.File.Id, d.File).Media(d.TmpFile).Do()
		if err != nil {
			errChan <- err
			return
		}
		fileChan <- f
		return
	}()
	select {
	case f := <-fileChan:
		d.File = f
		if d.TmpFile != nil && exists(d.TmpFile.Name()) {
			return os.Remove(d.TmpFile.Name())
		}
		return nil
	case err := <-errChan:
		return err
	case <-intr:
		return fuse.EINTR
	}
}
Flush a file tmp to google drive
package lib
import (
	"bazil.org/fuse"
	"bazil.org/fuse/fs"
	drive "code.google.com/p/google-api-go-client/drive/v2"
	"io/ioutil"
	"log"
	"os"
	"sync"
	"time"
)
type DriveFile struct {
	File     *drive.File
	TmpFile  *os.File
	Modified time.Time
	Created  time.Time
	Root     bool
	*sync.Mutex
}
func (d DriveFile) Attr() fuse.Attr {
	return fuse.Attr{
		Mode:  0644,
		Mtime: time.Now(),
		Size:  uint64(d.File.FileSize),
	}
}
func (d DriveFile) ReadAll(intr fs.Intr) ([]byte, fuse.Error) {
	d.Lock()
	defer d.Unlock()
	byteChan := make(chan *[]byte)
	errChan := make(chan error)
	defer func() {
		close(byteChan)
		close(errChan)
	}()
	go func() {
		log.Println(d.File.Title)
		b, err := client.Get(d.File.DownloadUrl)
		if err != nil {
			log.Println(err)
			errChan <- err
			return
		}
		c, err := ioutil.ReadAll(b.Body)
		if err != nil {
			log.Println(err)
			errChan <- err
		}
		byteChan <- &c
	}()
	select {
	case tmp := <-byteChan:
		return *tmp, nil
	case <-intr:
		return nil, nil
	}
}
func (d *DriveFile) Setattr(req *fuse.SetattrRequest, resp *fuse.SetattrResponse, intr fs.Intr) fuse.Error {
	valid := req.Valid
	if valid.Size() {
		return nil
	}
	return nil
}
func (d *DriveFile) Write(req *fuse.WriteRequest, resp *fuse.WriteResponse, intr fs.Intr) fuse.Error {
	d.Lock()
	defer d.Unlock()
	size, err := d.TmpFile.Write(req.Data)
	if err != nil {
		log.Println(err)
		return err
	}
	resp.Size = size
	return nil
}
func (d *DriveFile) Open(req *fuse.OpenRequest, resp *fuse.OpenResponse, intr fs.Intr) (fs.Handle, fuse.Error) {
	d.Lock()
	defer d.Unlock()
	d.TmpFile.Close()
	f, err := os.Create("/tmp/drivefs-" + d.File.Id)
	if err != nil {
		return nil, err
	}
	d.TmpFile = f
	resp.Flags &^= fuse.OpenDirectIO
	return d, nil
}