Skip to content

Commit

Permalink
fix get_xid for cross compilation
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
  • Loading branch information
wagoodman committed Feb 5, 2023
1 parent a2eecb6 commit 1ec3d77
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
21 changes: 21 additions & 0 deletions pkg/file/get_xid.go
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions pkg/file/get_xid_win.go
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 1 addition & 15 deletions pkg/file/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

0 comments on commit 1ec3d77

Please sign in to comment.