From fcd7f7200c97aecd6368fa017580bb771e36157c Mon Sep 17 00:00:00 2001 From: janson Date: Wed, 13 Mar 2024 14:51:18 +0800 Subject: [PATCH] build forkapp OK --- .gitignore | 2 ++ forkapp/build.sh | 5 +++++ forkapp/copydir.go | 15 ++++----------- forkapp/copydir_linux.go | 19 +++++++++++++++++++ forkapp/copydir_other.go | 8 ++++++++ 5 files changed, 38 insertions(+), 11 deletions(-) create mode 100755 forkapp/build.sh create mode 100644 forkapp/copydir_linux.go create mode 100644 forkapp/copydir_other.go diff --git a/.gitignore b/.gitignore index 6364b8e6..a7f45702 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ forkapp/forkapp tools/forkapp +forkapp/forkapp.exe +tools/forkapp.exe diff --git a/forkapp/build.sh b/forkapp/build.sh new file mode 100755 index 00000000..582553d2 --- /dev/null +++ b/forkapp/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -a -ldflags '-s -w -extldflags "-static"' -o forkapp +CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -a -ldflags '-s -w -extldflags "-static"' -o forkapp.exe + diff --git a/forkapp/copydir.go b/forkapp/copydir.go index f3a5d27e..e5baf550 100644 --- a/forkapp/copydir.go +++ b/forkapp/copydir.go @@ -5,7 +5,6 @@ import ( "io" "os" "path/filepath" - "syscall" ) type ChangePathFunc func(srcFile, dstFile string) string @@ -23,12 +22,7 @@ func CopyDirectory(scrDir, dest string, overwrite bool, changePathFn ChangePathF return err } - var statOk bool - stat, ok := fileInfo.Sys().(*syscall.Stat_t) - if ok { - statOk = true - } - + ostat := fileInfo.Sys() destPath := filepath.Join(dest, entry.Name()) destPath = changePathFn(sourcePath, destPath) @@ -50,10 +44,9 @@ func CopyDirectory(scrDir, dest string, overwrite bool, changePathFn ChangePathF } } - if statOk { - if err := os.Lchown(destPath, int(stat.Uid), int(stat.Gid)); err != nil { - return err - } + err = chown(destPath, ostat) + if err != nil { + return err } fInfo, err := entry.Info() diff --git a/forkapp/copydir_linux.go b/forkapp/copydir_linux.go new file mode 100644 index 00000000..fdfe717a --- /dev/null +++ b/forkapp/copydir_linux.go @@ -0,0 +1,19 @@ +//go:build linux +// +build linux + +package main + +import ( + "os" + "syscall" +) + +func chown(destPath string, ostat interface{}) error { + stat, ok := ostat.(*syscall.Stat_t) + if ok { + if err := os.Lchown(destPath, int(stat.Uid), int(stat.Gid)); err != nil { + return err + } + } + return nil +} diff --git a/forkapp/copydir_other.go b/forkapp/copydir_other.go new file mode 100644 index 00000000..bd877fcc --- /dev/null +++ b/forkapp/copydir_other.go @@ -0,0 +1,8 @@ +//go:build !linux +// +build !linux + +package main + +func chown(destPath string, ostat interface{}) error { + return nil +}