示例#1
0
// SetInodeAttributes sets specified attributes to file or directory.
//
// Required for fuse.FileSystem.
func (k *KodingNetworkFS) SetInodeAttributes(ctx context.Context, op *fuseops.SetInodeAttributesOp) error {
	entry, err := k.getEntry(ctx, op.Inode)
	if err != nil {
		return err
	}

	attrs := entry.GetAttrs()

	// optionally update attrs
	if op.Mode != nil {
		attrs.Mode = *op.Mode
	}
	if op.Atime != nil {
		attrs.Atime = *op.Atime
	}

	// optionally update attrs only if entry is a file
	if file, isFile := entry.(*File); isFile {
		if op.Mtime != nil {
			attrs.Mtime = *op.Mtime
		}

		if op.Size != nil {
			if err := file.TruncateTo(*op.Size); err != nil {
				return err
			}
			attrs.Size = *op.Size
		}
	}

	entry.SetAttrs(attrs)
	op.Attributes = *attrs

	return nil
}
示例#2
0
文件: goofys.go 项目: x5u/goofys
func (fs *Goofys) SetInodeAttributes(
	ctx context.Context,
	op *fuseops.SetInodeAttributesOp) (err error) {

	fs.mu.Lock()
	inode := fs.getInodeOrDie(op.Inode)
	fs.mu.Unlock()

	attr, err := inode.GetAttributes(fs)
	op.Attributes = *attr
	op.AttributesExpiration = time.Now().Add(365 * 24 * time.Hour)
	return
}
示例#3
0
func (fs *memFS) SetInodeAttributes(
	op *fuseops.SetInodeAttributesOp) (err error) {
	fs.mu.Lock()
	defer fs.mu.Unlock()

	// Grab the inode.
	inode := fs.getInodeOrDie(op.Inode)

	// Handle the request.
	inode.SetAttributes(op.Size, op.Mode, op.Mtime)

	// Fill in the response.
	op.Attributes = inode.attrs

	// We don't spontaneously mutate, so the kernel can cache as long as it wants
	// (since it also handles invalidation).
	op.AttributesExpiration = fs.clock.Now().Add(365 * 24 * time.Hour)

	return
}