2014-07-19 10:53:52 +02: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.
|
|
|
|
|
2018-09-24 23:46:21 +02:00
|
|
|
// +build js,wasm nacl
|
|
|
|
|
2014-07-19 10:53:52 +02:00
|
|
|
package os
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2016-02-03 22:58:02 +01:00
|
|
|
func fillFileStatFromSys(fs *fileStat, name string) {
|
|
|
|
fs.name = basename(name)
|
2016-07-22 20:15:38 +02:00
|
|
|
fs.size = fs.sys.Size
|
2016-02-03 22:58:02 +01:00
|
|
|
fs.modTime = timespecToTime(fs.sys.Mtime, fs.sys.MtimeNsec)
|
|
|
|
fs.mode = FileMode(fs.sys.Mode & 0777)
|
|
|
|
switch fs.sys.Mode & syscall.S_IFMT {
|
2014-07-19 10:53:52 +02:00
|
|
|
case syscall.S_IFBLK:
|
|
|
|
fs.mode |= ModeDevice
|
|
|
|
case syscall.S_IFCHR:
|
|
|
|
fs.mode |= ModeDevice | ModeCharDevice
|
|
|
|
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
|
|
|
|
}
|
2016-02-03 22:58:02 +01:00
|
|
|
if fs.sys.Mode&syscall.S_ISGID != 0 {
|
2014-07-19 10:53:52 +02:00
|
|
|
fs.mode |= ModeSetgid
|
|
|
|
}
|
2016-02-03 22:58:02 +01:00
|
|
|
if fs.sys.Mode&syscall.S_ISUID != 0 {
|
2014-07-19 10:53:52 +02:00
|
|
|
fs.mode |= ModeSetuid
|
|
|
|
}
|
2016-02-03 22:58:02 +01:00
|
|
|
if fs.sys.Mode&syscall.S_ISVTX != 0 {
|
2014-07-19 10:53:52 +02:00
|
|
|
fs.mode |= ModeSticky
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func timespecToTime(sec, nsec int64) time.Time {
|
|
|
|
return time.Unix(sec, nsec)
|
|
|
|
}
|
|
|
|
|
|
|
|
// For testing.
|
|
|
|
func atime(fi FileInfo) time.Time {
|
|
|
|
st := fi.Sys().(*syscall.Stat_t)
|
|
|
|
return timespecToTime(st.Atime, st.AtimeNsec)
|
|
|
|
}
|