move fillExtra to node.go

This commit is contained in:
Florian Weingarten
2015-04-29 03:45:24 +00:00
parent 91a2a5f90a
commit 6ba11d8fb7
3 changed files with 55 additions and 71 deletions

View File

@@ -15,43 +15,13 @@ func (node *Node) OpenForReading() (*os.File, error) {
return os.Open(node.path)
}
func (node *Node) fillExtra(path string, fi os.FileInfo) error {
stat, ok := fi.Sys().(*syscall.Stat_t)
if !ok {
return nil
}
func (node *Node) fillTimes(stat *syscall.Stat_t) {
node.ChangeTime = time.Unix(stat.Ctimespec.Unix())
node.AccessTime = time.Unix(stat.Atimespec.Unix())
node.UID = stat.Uid
node.GID = stat.Gid
}
if u, err := user.LookupId(strconv.Itoa(int(stat.Uid))); err == nil {
node.User = u.Username
}
node.Inode = stat.Ino
var err error
switch node.Type {
case "file":
node.Size = uint64(stat.Size)
node.Links = uint64(stat.Nlink)
case "dir":
case "symlink":
node.LinkTarget, err = os.Readlink(path)
case "dev":
node.Device = uint64(stat.Rdev)
case "chardev":
node.Device = uint64(stat.Rdev)
case "fifo":
case "socket":
default:
err = fmt.Errorf("invalid node type %q", node.Type)
}
return err
func (node *Node) fillDevice(stat *syscall.Stat_t) {
node.Device = uint64(stat.Rdev)
}
func (node *Node) createDevAt(path string) error {