diff --git a/lib/cp.go b/lib/cp.go index 1a49966..e9aa3b0 100644 --- a/lib/cp.go +++ b/lib/cp.go @@ -13,7 +13,6 @@ import ( "path" "path/filepath" "strings" - "syscall" "time" "github.com/gorilla/websocket" @@ -183,10 +182,7 @@ func cpToInstanceInternal(ctx context.Context, cfg CpConfig, opts CpToInstanceOp // Get UID/GID if archive mode is enabled var uid, gid uint32 if opts.Archive { - if stat, ok := srcInfo.Sys().(*syscall.Stat_t); ok { - uid = stat.Uid - gid = stat.Gid - } + uid, gid = getFileOwnership(srcInfo) } // Send initial request diff --git a/lib/stat_unix.go b/lib/stat_unix.go new file mode 100644 index 0000000..b827dd0 --- /dev/null +++ b/lib/stat_unix.go @@ -0,0 +1,16 @@ +//go:build unix + +package lib + +import ( + "io/fs" + "syscall" +) + +// getFileOwnership returns the UID and GID of a file on Unix systems. +func getFileOwnership(info fs.FileInfo) (uid, gid uint32) { + if stat, ok := info.Sys().(*syscall.Stat_t); ok { + return stat.Uid, stat.Gid + } + return 0, 0 +} diff --git a/lib/stat_windows.go b/lib/stat_windows.go new file mode 100644 index 0000000..5dfcaab --- /dev/null +++ b/lib/stat_windows.go @@ -0,0 +1,10 @@ +//go:build windows + +package lib + +import "io/fs" + +// getFileOwnership returns 0, 0 on Windows as UID/GID are Unix concepts. +func getFileOwnership(info fs.FileInfo) (uid, gid uint32) { + return 0, 0 +}