Skip to content

Commit

Permalink
Merge pull request #581 from nginx-proxy/fix-windows-build
Browse files Browse the repository at this point in the history
fix: windows build
  • Loading branch information
buchdag authored Dec 19, 2023
2 parents 6d352cb + f16820b commit 2ffde47
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
18 changes: 18 additions & 0 deletions internal/template/chown_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build linux || darwin

package template

import (
"io/fs"
"log"
"os"
"syscall"
)

func chown(dest *os.File, fi fs.FileInfo) {
if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
if err := dest.Chown(int(stat.Uid), int(stat.Gid)); err != nil {
log.Fatalf("Unable to chown temp file: %s\n", err)
}
}
}
12 changes: 12 additions & 0 deletions internal/template/chown_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build windows

package template

import (
"io/fs"
"os"
)

func chown(dest *os.File, fi fs.FileInfo) {
// do nothing
}
8 changes: 4 additions & 4 deletions internal/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"reflect"
"strconv"
"strings"
"syscall"
"text/template"
"unicode"

Expand Down Expand Up @@ -195,12 +194,13 @@ func GenerateFile(config config.Config, containers context.Context) bool {
fi, _ = os.Stat(config.Dest)
}
}

if err := dest.Chmod(fi.Mode()); err != nil {
log.Fatalf("Unable to chmod temp file: %s\n", err)
}
if err := dest.Chown(int(fi.Sys().(*syscall.Stat_t).Uid), int(fi.Sys().(*syscall.Stat_t).Gid)); err != nil {
log.Fatalf("Unable to chown temp file: %s\n", err)
}

chown(dest, fi)

oldContents, err = os.ReadFile(config.Dest)
if err != nil {
log.Fatalf("Unable to compare current file contents: %s: %s\n", config.Dest, err)
Expand Down

0 comments on commit 2ffde47

Please sign in to comment.