Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow os.FileInfo impls to provide a *file.FileInfo #132

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading