2021-08-23 09:14:53 -04:00
|
|
|
//go:build !windows
|
2015-05-07 18:14:11 -04:00
|
|
|
// +build !windows
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package system // import "github.com/docker/docker/pkg/system"
|
2014-11-13 15:36:05 -05:00
|
|
|
|
2017-05-23 10:22:32 -04:00
|
|
|
import (
|
2018-10-22 20:17:51 -04:00
|
|
|
"os"
|
2017-05-23 10:22:32 -04:00
|
|
|
"syscall"
|
|
|
|
)
|
2014-11-13 15:36:05 -05:00
|
|
|
|
2015-07-28 12:13:12 -04:00
|
|
|
// StatT type contains status of a file. It contains metadata
|
|
|
|
// like permission, owner, group, size, etc about a file.
|
|
|
|
type StatT struct {
|
2014-11-13 15:36:05 -05:00
|
|
|
mode uint32
|
|
|
|
uid uint32
|
|
|
|
gid uint32
|
|
|
|
rdev uint64
|
|
|
|
size int64
|
|
|
|
mtim syscall.Timespec
|
|
|
|
}
|
|
|
|
|
2015-07-28 12:13:12 -04:00
|
|
|
// Mode returns file's permission mode.
|
|
|
|
func (s StatT) Mode() uint32 {
|
2014-11-13 15:36:05 -05:00
|
|
|
return s.mode
|
|
|
|
}
|
|
|
|
|
2015-07-28 12:13:12 -04:00
|
|
|
// UID returns file's user id of owner.
|
|
|
|
func (s StatT) UID() uint32 {
|
2014-11-13 15:36:05 -05:00
|
|
|
return s.uid
|
|
|
|
}
|
|
|
|
|
2015-10-12 10:58:33 -04:00
|
|
|
// GID returns file's group id of owner.
|
|
|
|
func (s StatT) GID() uint32 {
|
2014-11-13 15:36:05 -05:00
|
|
|
return s.gid
|
|
|
|
}
|
|
|
|
|
2015-07-28 12:13:12 -04:00
|
|
|
// Rdev returns file's device ID (if it's special file).
|
|
|
|
func (s StatT) Rdev() uint64 {
|
2014-11-13 15:36:05 -05:00
|
|
|
return s.rdev
|
|
|
|
}
|
|
|
|
|
2015-07-28 12:13:12 -04:00
|
|
|
// Size returns file's size.
|
|
|
|
func (s StatT) Size() int64 {
|
2014-11-13 15:36:05 -05:00
|
|
|
return s.size
|
|
|
|
}
|
|
|
|
|
2015-07-28 12:13:12 -04:00
|
|
|
// Mtim returns file's last modification time.
|
|
|
|
func (s StatT) Mtim() syscall.Timespec {
|
2014-11-13 15:36:05 -05:00
|
|
|
return s.mtim
|
|
|
|
}
|
|
|
|
|
2017-11-27 16:11:11 -05:00
|
|
|
// IsDir reports whether s describes a directory.
|
|
|
|
func (s StatT) IsDir() bool {
|
|
|
|
return s.mode&syscall.S_IFDIR != 0
|
|
|
|
}
|
|
|
|
|
2017-04-05 18:35:43 -04:00
|
|
|
// Stat takes a path to a file and returns
|
|
|
|
// a system.StatT type pertaining to that file.
|
|
|
|
//
|
|
|
|
// Throws an error if the file does not exist
|
|
|
|
func Stat(path string) (*StatT, error) {
|
|
|
|
s := &syscall.Stat_t{}
|
|
|
|
if err := syscall.Stat(path, s); err != nil {
|
2018-12-19 17:57:06 -05:00
|
|
|
return nil, &os.PathError{Op: "Stat", Path: path, Err: err}
|
2017-04-05 18:35:43 -04:00
|
|
|
}
|
|
|
|
return fromStatT(s)
|
2014-11-13 15:36:05 -05:00
|
|
|
}
|