Esempio n. 1
0
func (f File) setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
	iter := f.Fs.Session.Query("SELECT created, modified, access, is_dir FROM fuse.filesystem WHERE filename=? AND entry='!' AND block=0;").Iter()
	var created uint64 = uint64(time.Now().Unix())
	var modified uint64 = created
	var access uint64 = created
	var is_dir bool = false
	var updated = false
	for iter.Scan(&created, &modified, &access, &is_dir) {
		if req.Valid&fuse.SetattrAtime != 0 {
			access = uint64(req.Atime.Unix())
		}
		if req.Valid&fuse.SetattrMtime != 0 {
			modified = uint64(req.Mtime.Unix())
		}
		if req.Valid&fuse.SetattrAtimeNow != 0 {
			access = uint64(time.Now().Unix())
		}
		if req.Valid&fuse.SetattrMtimeNow != 0 {
			modified = uint64(time.Now().Unix())
		}
		err := f.Fs.Session.Query("INSERT INTO fuse.filesystem(filename, entry, created, modified, access, block, data, is_dir) VALUES(?, ?, ?, ?, ?, ?, ?, ?);", f.GetPath(), "!", created, modified, access, 0, make([]byte, 0), is_dir).Exec()
		if err != nil {
			log.Error(err.Error())
			return err
		}
		updated = true
		break
	}
	if !updated {
		err := f.Fs.Session.Query("INSERT INTO fuse.filesystem(filename, entry, created, modified, access, block, data, is_dir) VALUES(?, ?, ?, ?, ?, ?, ?, ?);", f.GetPath(), "!", created, modified, access, 0, make([]byte, 0), is_dir).Exec()
		if err != nil {
			log.Error(err.Error())
			return err
		}
	}
	var size = req.Size
	if req.Valid&fuse.SetattrSize != 0 {
		err := f.doTruncate(size)
		if err != nil {
			log.Error(err.Error())
			return err
		}
	} else {
		var err error
		size, err = f.getSize()
		if err != nil {
			return err
		}
	}

	var mode os.FileMode
	if is_dir {
		mode = os.ModeDir
	} else {
		mode = 0
	}
	resp.Attr = fuse.Attr{Valid: time.Second, Inode: 0, Size: size, Atime: time.Unix(int64(access), 0), Mtime: time.Unix(int64(modified), 0), Ctime: time.Unix(int64(created), 0), Mode: mode}

	return nil
}
Esempio n. 2
0
// Set file attributes for this node
func (node *Node) Setattr(req *fuse.SetattrRequest, resp *fuse.SetattrResponse, intr fs.Intr) fuse.Error {
	// General
	if req.Valid.Mode() {
		node.Attrs.Mode = req.Mode
	}
	if req.Valid.Uid() {
		node.Attrs.Uid = req.Uid
	}
	if req.Valid.Gid() {
		node.Attrs.Gid = req.Gid
	}
	if req.Valid.Size() {
		node.Attrs.Size = req.Size
	}
	if req.Valid.Atime() {
		node.Attrs.Atime = req.Atime
	}
	if req.Valid.Mtime() {
		node.Attrs.Mtime = req.Mtime
	}
	// OSX specific
	if req.Valid.Crtime() {
		node.Attrs.Crtime = req.Crtime
	}
	if req.Valid.Flags() {
		node.Attrs.Flags = req.Flags
	}
	resp.Attr = node.Attrs
	node.dirty = true
	return nil
}