Skip to content

Commit

Permalink
feat: add support for all upstream dist to file package (#226)
Browse files Browse the repository at this point in the history
use specific function for unix goos and fallback for non-unix systems
  • Loading branch information
kruskall authored Sep 3, 2024
1 parent 8ec6b25 commit 999dd7a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 66 deletions.
9 changes: 9 additions & 0 deletions file/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ func Lstat(name string) (FileInfo, error) {
return stat(name, os.Lstat)
}

func stat(name string, statFunc func(name string) (os.FileInfo, error)) (FileInfo, error) {
info, err := statFunc(name)
if err != nil {
return nil, err
}

return wrap(info)
}

// Wrap wraps the given os.FileInfo and returns a FileInfo in order to expose
// the UID and GID in a uniform manner across operating systems.
func Wrap(info os.FileInfo) (FileInfo, error) {
Expand Down
11 changes: 2 additions & 9 deletions file/fileinfo_windows.go → file/fileinfo_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@
// specific language governing permissions and limitations
// under the License.

//go:build !unix

package file

import (
"os"
)

func stat(name string, statFunc func(name string) (os.FileInfo, error)) (FileInfo, error) {
info, err := statFunc(name)
if err != nil {
return nil, err
}

return wrap(info)
}

func wrap(info os.FileInfo) (FileInfo, error) {
return fileInfo{FileInfo: info}, nil
}
48 changes: 0 additions & 48 deletions file/fileinfo_plan9.go

This file was deleted.

9 changes: 0 additions & 9 deletions file/fileinfo_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ import (
"syscall"
)

func stat(name string, statFunc func(name string) (os.FileInfo, error)) (FileInfo, error) {
info, err := statFunc(name)
if err != nil {
return nil, err
}

return wrap(info)
}

func wrap(info os.FileInfo) (FileInfo, error) {
stat, ok := info.Sys().(*syscall.Stat_t)
if !ok {
Expand Down

0 comments on commit 999dd7a

Please sign in to comment.