Skip to content

Commit

Permalink
build forkapp OK
Browse files Browse the repository at this point in the history
  • Loading branch information
mjanson committed Mar 13, 2024
1 parent bb7e05e commit fcd7f72
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

forkapp/forkapp
tools/forkapp
forkapp/forkapp.exe
tools/forkapp.exe
5 changes: 5 additions & 0 deletions forkapp/build.sh
Original file line number Diff line number Diff line change
@@ -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

15 changes: 4 additions & 11 deletions forkapp/copydir.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io"
"os"
"path/filepath"
"syscall"
)

type ChangePathFunc func(srcFile, dstFile string) string
Expand All @@ -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)

Expand All @@ -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()
Expand Down
19 changes: 19 additions & 0 deletions forkapp/copydir_linux.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions forkapp/copydir_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !linux
// +build !linux

package main

func chown(destPath string, ostat interface{}) error {
return nil
}

0 comments on commit fcd7f72

Please sign in to comment.