From 46dc76f5daa5e1186a5c4f2299bd4b4ff82e60d0 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Sun, 12 Feb 2012 09:17:57 +1100 Subject: [PATCH] go1: update recipe for recovering Stat_t Fixes #2983. R=golang-dev, gri CC=golang-dev https://golang.org/cl/5654063 --- doc/go1.html | 12 ++++-------- doc/go1.tmpl | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/doc/go1.html b/doc/go1.html index 0dc73234f6e..6e63882f09f 100644 --- a/doc/go1.html +++ b/doc/go1.html @@ -1420,6 +1420,7 @@ changing it from a struct to an interface: Mode() FileMode // file mode bits ModTime() time.Time // modification time IsDir() bool // abbreviation for Mode().IsDir() + Sys() interface{} // underlying data source (can return nil) } @@ -1435,7 +1436,7 @@ The system-specific details of file modes and properties such as (on Unix) i-number have been removed from FileInfo altogether. Instead, each operating system's os package provides an implementation of the FileInfo interface, *os.FileStat, -which in turn contains a Sys field that stores the +which has a Sys method that returns the system-specific representation of file metadata. For instance, to discover the i-number of a file on a Unix system, unpack the FileInfo like this: @@ -1446,13 +1447,8 @@ the FileInfo like this: if err != nil { log.Fatal(err) } - // Make sure it's an implementation known to package os. - fileStat, ok := fi.(*os.FileStat) - if !ok { - log.Fatal("hello.go: not an os File") - } - // Now check that it's a Unix file. - unixStat, ok := fileStat.Sys.(*syscall.Stat_t) + // Check that it's a Unix file. + unixStat, ok := fi.Sys().(*syscall.Stat_t) if !ok { log.Fatal("hello.go: not a Unix file") } diff --git a/doc/go1.tmpl b/doc/go1.tmpl index c75f2fe7469..862fe0ed435 100644 --- a/doc/go1.tmpl +++ b/doc/go1.tmpl @@ -1323,6 +1323,7 @@ changing it from a struct to an interface: Mode() FileMode // file mode bits ModTime() time.Time // modification time IsDir() bool // abbreviation for Mode().IsDir() + Sys() interface{} // underlying data source (can return nil) } @@ -1338,7 +1339,7 @@ The system-specific details of file modes and properties such as (on Unix) i-number have been removed from FileInfo altogether. Instead, each operating system's os package provides an implementation of the FileInfo interface, *os.FileStat, -which in turn contains a Sys field that stores the +which has a Sys method that returns the system-specific representation of file metadata. For instance, to discover the i-number of a file on a Unix system, unpack the FileInfo like this: @@ -1349,13 +1350,8 @@ the FileInfo like this: if err != nil { log.Fatal(err) } - // Make sure it's an implementation known to package os. - fileStat, ok := fi.(*os.FileStat) - if !ok { - log.Fatal("hello.go: not an os File") - } - // Now check that it's a Unix file. - unixStat, ok := fileStat.Sys.(*syscall.Stat_t) + // Check that it's a Unix file. + unixStat, ok := fi.Sys().(*syscall.Stat_t) if !ok { log.Fatal("hello.go: not a Unix file") }