os: turn FileStat.Sys into a method on FileInfo
This reduces the overhead necessary to work with OS-specific
file details, hides the implementation of FileStat, and
preserves the implementation-specific nature of Sys.
Expressions such as:
stat.(*os.FileInfo).Sys.(*syscall.Stat_t).Uid
fi1.(*os.FileStat).SameFile(fi2.(*os.FileStat))
Are now spelled as::
stat.Sys().(*syscall.Stat_t).Uid
os.SameFile(fi1, fi2)
R=cw, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/5448079
diff --git a/src/pkg/os/stat_plan9.go b/src/pkg/os/stat_plan9.go
index f731e43..7c2d1bd 100644
--- a/src/pkg/os/stat_plan9.go
+++ b/src/pkg/os/stat_plan9.go
@@ -9,18 +9,18 @@
"time"
)
-func sameFile(fs1, fs2 *FileStat) bool {
- a := fs1.Sys.(*Dir)
- b := fs2.Sys.(*Dir)
+func sameFile(sys1, sys2 interface{}) bool {
+ a := sys1.(*Dir)
+ b := sys2.(*Dir)
return a.Qid.Path == b.Qid.Path && a.Type == b.Type && a.Dev == b.Dev
}
func fileInfoFromStat(d *Dir) FileInfo {
- fs := &FileStat{
+ fs := &fileStat{
name: d.Name,
size: int64(d.Length),
modTime: time.Unix(int64(d.Mtime), 0),
- Sys: d,
+ sys: d,
}
fs.mode = FileMode(d.Mode & 0777)
if d.Mode&syscall.DMDIR != 0 {
@@ -100,5 +100,5 @@
// For testing.
func atime(fi FileInfo) time.Time {
- return time.Unix(int64(fi.(*FileStat).Sys.(*Dir).Atime), 0)
+ return time.Unix(int64(fi.Sys().(*Dir).Atime), 0)
}