Skip to content

Commit

Permalink
Merge pull request #132 from ozkatz/feat/optional-fileinfo
Browse files Browse the repository at this point in the history
Allow os.FileInfo impls to provide a *file.FileInfo
  • Loading branch information
willscott authored Apr 13, 2024
2 parents 578b735 + 29e3699 commit ea1b85e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ type FileInfo struct {

// GetInfo extracts some non-standardized items from the result of a Stat call.
func GetInfo(fi os.FileInfo) *FileInfo {
return getInfo(fi)
sys := fi.Sys()
switch v := sys.(type) {
case FileInfo:
return &v
case *FileInfo:
return v
default:
return getOSFileInfo(fi)
}
}
2 changes: 1 addition & 1 deletion file/file_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"golang.org/x/sys/unix"
)

func getInfo(info os.FileInfo) *FileInfo {
func getOSFileInfo(info os.FileInfo) *FileInfo {
fi := &FileInfo{}
if s, ok := info.Sys().(*syscall.Stat_t); ok {
fi.Nlink = uint32(s.Nlink)
Expand Down
2 changes: 1 addition & 1 deletion file/file_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package file

import "os"

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

Expand Down

0 comments on commit ea1b85e

Please sign in to comment.