2009-06-04 14:33:57 -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
|
|
|
|
|
2009-08-12 14:18:37 -06:00
|
|
|
import "syscall"
|
2009-06-04 14:33:57 -06:00
|
|
|
|
|
|
|
func isSymlink(stat *syscall.Stat_t) bool {
|
2009-11-09 22:23:52 -07:00
|
|
|
return stat.Mode&syscall.S_IFMT == syscall.S_IFLNK
|
2009-06-04 14:33:57 -06:00
|
|
|
}
|
|
|
|
|
2010-04-09 12:36:40 -06:00
|
|
|
func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *FileInfo {
|
|
|
|
fi.Dev = uint64(stat.Dev)
|
|
|
|
fi.Ino = stat.Ino
|
|
|
|
fi.Nlink = uint64(stat.Nlink)
|
|
|
|
fi.Mode = uint32(stat.Mode)
|
2010-04-22 15:01:33 -06:00
|
|
|
fi.Uid = int(stat.Uid)
|
|
|
|
fi.Gid = int(stat.Gid)
|
2010-04-09 12:36:40 -06:00
|
|
|
fi.Rdev = uint64(stat.Rdev)
|
2010-04-22 15:01:33 -06:00
|
|
|
fi.Size = stat.Size
|
|
|
|
fi.Blksize = int64(stat.Blksize)
|
|
|
|
fi.Blocks = stat.Blocks
|
|
|
|
fi.Atime_ns = syscall.TimespecToNsec(stat.Atimespec)
|
|
|
|
fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtimespec)
|
|
|
|
fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctimespec)
|
2011-03-29 12:23:36 -06:00
|
|
|
fi.Name = basename(name)
|
2009-06-04 14:33:57 -06:00
|
|
|
if isSymlink(lstat) && !isSymlink(stat) {
|
2010-04-09 12:36:40 -06:00
|
|
|
fi.FollowedSymlink = true
|
2009-06-04 14:33:57 -06:00
|
|
|
}
|
2010-04-09 12:36:40 -06:00
|
|
|
return fi
|
2009-06-04 14:33:57 -06:00
|
|
|
}
|