2011-08-08 07:56:36 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package os
|
|
|
|
|
2011-11-30 10:01:46 -07:00
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
)
|
2011-08-08 07:56:36 -06:00
|
|
|
|
2015-10-28 04:58:58 -06:00
|
|
|
func fillFileStatFromSys(fs *fileStat, name string) {
|
|
|
|
fs.name = basename(name)
|
2016-04-14 20:09:36 -06:00
|
|
|
fs.size = fs.sys.Size
|
2015-10-28 04:58:58 -06:00
|
|
|
fs.modTime = timespecToTime(fs.sys.Mtim)
|
|
|
|
fs.mode = FileMode(fs.sys.Mode & 0777)
|
|
|
|
switch fs.sys.Mode & syscall.S_IFMT {
|
2012-01-09 15:22:53 -07:00
|
|
|
case syscall.S_IFBLK:
|
2011-11-30 10:04:16 -07:00
|
|
|
fs.mode |= ModeDevice
|
2012-01-09 15:22:53 -07:00
|
|
|
case syscall.S_IFCHR:
|
|
|
|
fs.mode |= ModeDevice | ModeCharDevice
|
2011-11-30 10:04:16 -07:00
|
|
|
case syscall.S_IFDIR:
|
|
|
|
fs.mode |= ModeDir
|
|
|
|
case syscall.S_IFIFO:
|
|
|
|
fs.mode |= ModeNamedPipe
|
|
|
|
case syscall.S_IFLNK:
|
|
|
|
fs.mode |= ModeSymlink
|
|
|
|
case syscall.S_IFREG:
|
|
|
|
// nothing to do
|
|
|
|
case syscall.S_IFSOCK:
|
|
|
|
fs.mode |= ModeSocket
|
|
|
|
}
|
2015-10-28 04:58:58 -06:00
|
|
|
if fs.sys.Mode&syscall.S_ISGID != 0 {
|
2011-11-30 10:04:16 -07:00
|
|
|
fs.mode |= ModeSetgid
|
|
|
|
}
|
2015-10-28 04:58:58 -06:00
|
|
|
if fs.sys.Mode&syscall.S_ISUID != 0 {
|
2011-11-30 10:04:16 -07:00
|
|
|
fs.mode |= ModeSetuid
|
|
|
|
}
|
2015-10-28 04:58:58 -06:00
|
|
|
if fs.sys.Mode&syscall.S_ISVTX != 0 {
|
2012-01-19 12:29:24 -07:00
|
|
|
fs.mode |= ModeSticky
|
|
|
|
}
|
2011-08-08 07:56:36 -06:00
|
|
|
}
|
2011-11-30 10:01:46 -07:00
|
|
|
|
|
|
|
func timespecToTime(ts syscall.Timespec) time.Time {
|
2016-04-14 20:09:36 -06:00
|
|
|
return time.Unix(ts.Sec, int64(ts.Nsec))
|
2011-11-30 10:01:46 -07:00
|
|
|
}
|
2011-11-30 10:04:16 -07:00
|
|
|
|
|
|
|
// For testing.
|
|
|
|
func atime(fi FileInfo) time.Time {
|
2012-02-02 19:16:18 -07:00
|
|
|
return timespecToTime(fi.Sys().(*syscall.Stat_t).Atim)
|
2011-11-30 10:04:16 -07:00
|
|
|
}
|