Better stat functionality

This commit is contained in:
Alex Yatskov 2015-05-16 23:04:34 +09:00
parent 148d9879d5
commit eed33efdc8
3 changed files with 20 additions and 3 deletions

2
dir.go
View File

@ -47,7 +47,7 @@ func newVersionedDir(node *versionedNode, inode uint64) *versionedDir {
func (this versionedDir) Attr(attr *fuse.Attr) {
log.Printf("versionedDir::Attr: %s", this.node)
attr.Mode = this.node.info.Mode()
this.node.attr(attr)
attr.Inode = this.inode
}

View File

@ -41,9 +41,8 @@ func newVersionedFile(node *versionedNode, inode uint64) *versionedFile {
func (this versionedFile) Attr(attr *fuse.Attr) {
log.Printf("versionedFile::Attr: %s", this.node)
attr.Mode = this.node.info.Mode()
this.node.attr(attr)
attr.Inode = this.inode
attr.Size = uint64(this.node.info.Size())
}
func (this versionedFile) ReadAll(ctx context.Context) ([]byte, error) {

18
node.go
View File

@ -23,8 +23,11 @@
package main
import (
"bazil.org/fuse"
"fmt"
"os"
"syscall"
"time"
)
type versionedNode struct {
@ -39,6 +42,21 @@ func (this *versionedNode) rebasedPath() string {
return this.ver.rebasePath(this.path)
}
func (this *versionedNode) attr(attr *fuse.Attr) {
stat := this.info.Sys().(*syscall.Stat_t)
attr.Size = uint64(this.info.Size())
attr.Blocks = uint64(stat.Blocks)
attr.Atime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
attr.Mtime = this.info.ModTime()
attr.Ctime = time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec))
attr.Mode = this.info.Mode()
attr.Nlink = uint32(stat.Nlink)
attr.Uid = stat.Uid
attr.Gid = stat.Gid
attr.Rdev = uint32(stat.Rdev)
}
func (this *versionedNode) String() string {
return fmt.Sprintf("%s (%s)", this.path, this.rebasedPath())
}