Skip to content

Commit ea1b85e

Browse files
authored
Merge pull request #132 from ozkatz/feat/optional-fileinfo
Allow os.FileInfo impls to provide a *file.FileInfo
2 parents 578b735 + 29e3699 commit ea1b85e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

file/file.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,13 @@ type FileInfo struct {
1313

1414
// GetInfo extracts some non-standardized items from the result of a Stat call.
1515
func GetInfo(fi os.FileInfo) *FileInfo {
16-
return getInfo(fi)
16+
sys := fi.Sys()
17+
switch v := sys.(type) {
18+
case FileInfo:
19+
return &v
20+
case *FileInfo:
21+
return v
22+
default:
23+
return getOSFileInfo(fi)
24+
}
1725
}

file/file_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"golang.org/x/sys/unix"
1010
)
1111

12-
func getInfo(info os.FileInfo) *FileInfo {
12+
func getOSFileInfo(info os.FileInfo) *FileInfo {
1313
fi := &FileInfo{}
1414
if s, ok := info.Sys().(*syscall.Stat_t); ok {
1515
fi.Nlink = uint32(s.Nlink)

file/file_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package file
44

55
import "os"
66

7-
func getInfo(info os.FileInfo) *FileInfo {
7+
func getOSFileInfo(info os.FileInfo) *FileInfo {
88
// https://godoc.org/golang.org/x/sys/windows#GetFileInformationByHandle
99
// can be potentially used to populate Nlink
1010

0 commit comments

Comments
 (0)