2014-02-21 13:12:25 +04:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2015-03-31 11:03:31 +03:00
|
|
|
// fromStatT converts a syscall.Stat_t type to a system.Stat_t type
|
2015-07-28 19:13:12 +03:00
|
|
|
func fromStatT(s *syscall.Stat_t) (*StatT, error) {
|
|
|
|
return &StatT{size: s.Size,
|
2014-11-13 23:36:05 +03:00
|
|
|
mode: s.Mode,
|
|
|
|
uid: s.Uid,
|
|
|
|
gid: s.Gid,
|
|
|
|
rdev: s.Rdev,
|
|
|
|
mtim: s.Mtim}, nil
|
2014-02-21 13:12:25 +04:00
|
|
|
}
|
2015-03-11 18:42:49 +03:00
|
|
|
|
2015-07-28 19:13:12 +03:00
|
|
|
// FromStatT exists only on linux, and loads a system.StatT from a
|
2015-04-14 22:28:54 +03:00
|
|
|
// syscal.Stat_t.
|
2015-07-28 19:13:12 +03:00
|
|
|
func FromStatT(s *syscall.Stat_t) (*StatT, error) {
|
2015-04-14 22:28:54 +03:00
|
|
|
return fromStatT(s)
|
|
|
|
}
|
|
|
|
|
2015-03-31 11:03:31 +03:00
|
|
|
// Stat takes a path to a file and returns
|
2015-07-28 19:13:12 +03:00
|
|
|
// a system.StatT type pertaining to that file.
|
2015-03-31 11:03:31 +03:00
|
|
|
//
|
|
|
|
// Throws an error if the file does not exist
|
2015-07-28 19:13:12 +03:00
|
|
|
func Stat(path string) (*StatT, error) {
|
2015-03-11 18:42:49 +03:00
|
|
|
s := &syscall.Stat_t{}
|
2015-04-26 19:50:25 +03:00
|
|
|
if err := syscall.Stat(path, s); err != nil {
|
2015-03-11 18:42:49 +03:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return fromStatT(s)
|
|
|
|
}
|