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

Windows build #60

Merged
merged 4 commits into from
Oct 17, 2022
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
2 changes: 1 addition & 1 deletion .github/build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ D=$(pwd)
#
# We build on multiple platforms/archs
#
BUILD_PLATFORMS="linux darwin freebsd"
BUILD_PLATFORMS="linux darwin freebsd windows"
BUILD_ARCHS="amd64 386"

# For each platform
Expand Down
15 changes: 10 additions & 5 deletions builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"sort"
"strconv"
"strings"
"syscall"
"time"

"github.com/skx/yal/env"
Expand Down Expand Up @@ -631,10 +630,16 @@ func fileStatFn(env *env.Environment, args []primitive.Primitive) primitive.Prim
UID := os.Getuid()
GID := os.Getgid()

// But if we can get the "real" values, then use them.
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
UID = int(stat.Uid)
GID = int(stat.Gid)
// Get the UID in a non-portable way
u, e := getUID(info)
if e == nil {
UID = u
}

// Get the GID in a non-portable way
g, e := getGID(info)
if e == nil {
GID = g
}

var res primitive.List
Expand Down
4 changes: 2 additions & 2 deletions builtins/builtins_shell_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !windows && !darwin
// +build !windows,!darwin
//go:build !windows
// +build !windows

package builtins

Expand Down
31 changes: 31 additions & 0 deletions builtins/file_info_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build !windows

package builtins

import (
"os"
"syscall"
)

// getGID returns the group of the file, from the extended information
// available after a stat - that is not portable to Windows though.
//
// This is in a separate file so that we use build-tags to build code
// appropriately.
func getGID(info os.FileInfo) (int, error) {

stat, _ := info.Sys().(*syscall.Stat_t)
return int(stat.Gid), nil
}


// getUID returns the owner of the file, from the extended information
// available after a stat - that is not portable to Windows though.
//
// This is in a separate file so that we use build-tags to build code
// appropriately.
func getUID(info os.FileInfo) (int, error) {

stat, _ := info.Sys().(*syscall.Stat_t)
return int(stat.Uid), nil
}
34 changes: 34 additions & 0 deletions builtins/file_info_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//go:build windows

package builtins

import (
"fmt"
"os"
)

// getGID should return the group of the file, from the extended information
// available after a stat, however on Windows platforms that doesn't work
// in the obvious way.
//
// Here we just return an error to make that apparent to the caller.
//
// This is in a separate file so that we use build-tags to build code
// appropriately.
func getGID(info os.FileInfo) (int, error) {

return 0, fmt.Errorf("not found")
}

// getUID should return the owner of the file, from the extended information
// available after a stat, however on Windows platforms that doesn't work
// in the obvious way.
//
// Here we just return an error to make that apparent to the caller.
//
// This is in a separate file so that we use build-tags to build code
// appropriately.
func getUID(info os.FileInfo) (int, error) {

return 0, fmt.Errorf("not found")
}