Skip to content

Commit 2ffde47

Browse files
authored
Merge pull request #581 from nginx-proxy/fix-windows-build
fix: windows build
2 parents 6d352cb + f16820b commit 2ffde47

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

internal/template/chown_unix.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//go:build linux || darwin
2+
3+
package template
4+
5+
import (
6+
"io/fs"
7+
"log"
8+
"os"
9+
"syscall"
10+
)
11+
12+
func chown(dest *os.File, fi fs.FileInfo) {
13+
if stat, ok := fi.Sys().(*syscall.Stat_t); ok {
14+
if err := dest.Chown(int(stat.Uid), int(stat.Gid)); err != nil {
15+
log.Fatalf("Unable to chown temp file: %s\n", err)
16+
}
17+
}
18+
}

internal/template/chown_windows.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build windows
2+
3+
package template
4+
5+
import (
6+
"io/fs"
7+
"os"
8+
)
9+
10+
func chown(dest *os.File, fi fs.FileInfo) {
11+
// do nothing
12+
}

internal/template/template.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"reflect"
1414
"strconv"
1515
"strings"
16-
"syscall"
1716
"text/template"
1817
"unicode"
1918

@@ -195,12 +194,13 @@ func GenerateFile(config config.Config, containers context.Context) bool {
195194
fi, _ = os.Stat(config.Dest)
196195
}
197196
}
197+
198198
if err := dest.Chmod(fi.Mode()); err != nil {
199199
log.Fatalf("Unable to chmod temp file: %s\n", err)
200200
}
201-
if err := dest.Chown(int(fi.Sys().(*syscall.Stat_t).Uid), int(fi.Sys().(*syscall.Stat_t).Gid)); err != nil {
202-
log.Fatalf("Unable to chown temp file: %s\n", err)
203-
}
201+
202+
chown(dest, fi)
203+
204204
oldContents, err = os.ReadFile(config.Dest)
205205
if err != nil {
206206
log.Fatalf("Unable to compare current file contents: %s: %s\n", config.Dest, err)

0 commit comments

Comments
 (0)