From 1ec3d77533156b5120d2ad4bec5aaebf5bb7c208 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Sun, 5 Feb 2023 10:02:52 -0500 Subject: [PATCH] fix get_xid for cross compilation Signed-off-by: Alex Goodman --- pkg/file/get_xid.go | 21 +++++++++++++++++++++ pkg/file/get_xid_win.go | 13 +++++++++++++ pkg/file/metadata.go | 16 +--------------- 3 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 pkg/file/get_xid.go create mode 100644 pkg/file/get_xid_win.go diff --git a/pkg/file/get_xid.go b/pkg/file/get_xid.go new file mode 100644 index 00000000..b59eb795 --- /dev/null +++ b/pkg/file/get_xid.go @@ -0,0 +1,21 @@ +//go:build linux || darwin || netbsd +// +build linux darwin netbsd + +package file + +import ( + "os" + "syscall" +) + +// getXid is the UID GID system info for unix +func getXid(info os.FileInfo) (uid, gid int) { + uid = -1 + gid = -1 + if stat, ok := info.Sys().(*syscall.Stat_t); ok { + uid = int(stat.Uid) + gid = int(stat.Gid) + } + + return uid, gid +} diff --git a/pkg/file/get_xid_win.go b/pkg/file/get_xid_win.go new file mode 100644 index 00000000..91083371 --- /dev/null +++ b/pkg/file/get_xid_win.go @@ -0,0 +1,13 @@ +//go:build windows +// +build windows + +package file + +import ( + "os" +) + +// getXid is a placeholder for windows file information +func getXid(info os.FileInfo) (uid, gid int) { + return -1, -1 +} diff --git a/pkg/file/metadata.go b/pkg/file/metadata.go index 7ba0014f..5ba884af 100644 --- a/pkg/file/metadata.go +++ b/pkg/file/metadata.go @@ -2,13 +2,11 @@ package file import ( "archive/tar" + "github.com/anchore/stereoscope/internal/log" "io" "os" "path" "path/filepath" - "syscall" - - "github.com/anchore/stereoscope/internal/log" "github.com/sylabs/squashfs" ) @@ -126,15 +124,3 @@ func NewMetadataFromPath(path string, info os.FileInfo) Metadata { IsDir: info.IsDir(), } } - -// getXid is the UID GID system info for unix -func getXid(info os.FileInfo) (uid, gid int) { - uid = -1 - gid = -1 - if stat, ok := info.Sys().(*syscall.Stat_t); ok { - uid = int(stat.Uid) - gid = int(stat.Gid) - } - - return uid, gid -}