Skip to content

Commit fd74c45

Browse files
committed
fix: enable Windows cross-compilation
Move syscall.Stat_t usage to platform-specific files since it's Unix-only. On Windows, getFileOwnership() returns 0, 0 as UID/GID are Unix concepts. This allows the SDK to be cross-compiled for Windows targets.
1 parent 084d4f0 commit fd74c45

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

lib/cp.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"path"
1414
"path/filepath"
1515
"strings"
16-
"syscall"
1716
"time"
1817

1918
"github.com/gorilla/websocket"
@@ -183,10 +182,7 @@ func cpToInstanceInternal(ctx context.Context, cfg CpConfig, opts CpToInstanceOp
183182
// Get UID/GID if archive mode is enabled
184183
var uid, gid uint32
185184
if opts.Archive {
186-
if stat, ok := srcInfo.Sys().(*syscall.Stat_t); ok {
187-
uid = stat.Uid
188-
gid = stat.Gid
189-
}
185+
uid, gid = getFileOwnership(srcInfo)
190186
}
191187

192188
// Send initial request

lib/stat_unix.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build unix
2+
3+
package lib
4+
5+
import (
6+
"io/fs"
7+
"syscall"
8+
)
9+
10+
// getFileOwnership returns the UID and GID of a file on Unix systems.
11+
func getFileOwnership(info fs.FileInfo) (uid, gid uint32) {
12+
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
13+
return stat.Uid, stat.Gid
14+
}
15+
return 0, 0
16+
}

lib/stat_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build windows
2+
3+
package lib
4+
5+
import "io/fs"
6+
7+
// getFileOwnership returns 0, 0 on Windows as UID/GID are Unix concepts.
8+
func getFileOwnership(info fs.FileInfo) (uid, gid uint32) {
9+
return 0, 0
10+
}

0 commit comments

Comments
 (0)