diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 5a02c3a2de..3f605feab4 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -38,13 +38,13 @@ jobs: steps: - name: "Fetch source code" uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - id: diff + - id: diff run: | git fetch --no-tags --prune --no-recurse-submodules --depth=1 origin ${{github.event.pull_request.base.ref}} echo "go=$(git diff --name-only origin/${{github.event.pull_request.base.ref}} | grep -e '\.go' -e '\.github' -e 'go\.mod' -e 'go\.sum' -e '\.tf' -e '\.gitattributes' | wc -l)" | tee -a "$GITHUB_OUTPUT" outputs: go: ${{ steps.diff.outputs.go }} - + unit-tests: name: Unit tests for ${{ matrix.goos }}_${{ matrix.goarch }} runs-on: ${{ matrix.runson }} @@ -175,7 +175,7 @@ jobs: # possible for someone who encounters a failure here to replicate # exactly the same run in their local development environment. make golangci-lint - + - name: "Copyright headers" run: | go tool github.com/hashicorp/copywrite headers --plan diff --git a/.gitignore b/.gitignore index bc924fc854..81cee9e849 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,9 @@ website/node_modules website/vendor vendor/ +# "make golangci-lint" places its temprary golangci-lint executable here +tools/golangci-lint* + # VSCode debugging configurations .vscode/launch.json diff --git a/Makefile b/Makefile index 469c6abf16..31a0e2192e 100644 --- a/Makefile +++ b/Makefile @@ -46,10 +46,12 @@ generate: protobuf: go run ./tools/protobuf-compile . -# Golangci-lint +# Golangci-lint is installed first and then run twice to cover all platforms. .PHONY: golangci-lint golangci-lint: - go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.0 run --timeout 60m ./... + GOBIN=$(PWD)/tools go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.0 + GOOS=windows tools/golangci-lint${EXT} run --timeout 60m ./... + GOOS=linux tools/golangci-lint${EXT} run --timeout 60m ./... # Run license check .PHONY: license-check diff --git a/internal/flock/filesystem_lock_windows.go b/internal/flock/filesystem_lock_windows.go index 21884b7c69..676e1318c2 100644 --- a/internal/flock/filesystem_lock_windows.go +++ b/internal/flock/filesystem_lock_windows.go @@ -10,6 +10,7 @@ package flock import ( "context" "errors" + "log" "math" "os" "syscall" @@ -40,7 +41,12 @@ func Lock(f *os.File) error { if err != nil { return err } - defer syscall.CloseHandle(ol.HEvent) + defer func() { + err := syscall.CloseHandle(ol.HEvent) + if err != nil { + log.Printf("[ERROR] failed to close file locking event handle: %v", err) + } + }() return lockFileEx( syscall.Handle(f.Fd()), @@ -96,9 +102,8 @@ func Unlock(*os.File) error { } func lockFileEx(h syscall.Handle, flags, reserved, locklow, lockhigh uint32, ol *syscall.Overlapped) (err error) { - r1, _, e1 := syscall.Syscall6( + r1, _, e1 := syscall.SyscallN( procLockFileEx.Addr(), - 6, uintptr(h), uintptr(flags), uintptr(reserved), @@ -136,9 +141,8 @@ func createEvent(sa *syscall.SecurityAttributes, manualReset bool, initialState _p1 = 1 } - r0, _, e1 := syscall.Syscall6( + r0, _, e1 := syscall.SyscallN( procCreateEventW.Addr(), - 4, uintptr(unsafe.Pointer(sa)), uintptr(_p0), uintptr(_p1), diff --git a/internal/replacefile/replacefile_windows.go b/internal/replacefile/replacefile_windows.go index a04b0ac031..e64bd100ad 100644 --- a/internal/replacefile/replacefile_windows.go +++ b/internal/replacefile/replacefile_windows.go @@ -29,17 +29,17 @@ func AtomicRename(source, destination string) error { // existing file. srcPtr, err := syscall.UTF16PtrFromString(source) if err != nil { - return &os.LinkError{"replace", source, destination, err} + return &os.LinkError{Op: "replace", Old: source, New: destination, Err: err} } destPtr, err := syscall.UTF16PtrFromString(destination) if err != nil { - return &os.LinkError{"replace", source, destination, err} + return &os.LinkError{Op: "replace", Old: source, New: destination, Err: err} } flags := uint32(windows.MOVEFILE_REPLACE_EXISTING | windows.MOVEFILE_WRITE_THROUGH) err = windows.MoveFileEx(srcPtr, destPtr, flags) if err != nil { - return &os.LinkError{"replace", source, destination, err} + return &os.LinkError{Op: "replace", Old: source, New: destination, Err: err} } return nil } diff --git a/internal/terminal/impl_windows.go b/internal/terminal/impl_windows.go index 9815f510dd..ffa77ab0d2 100644 --- a/internal/terminal/impl_windows.go +++ b/internal/terminal/impl_windows.go @@ -142,7 +142,7 @@ const CP_UTF8 = 65001 // interface.) func SetConsoleCP(codepageID uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetConsoleCP.Addr(), 1, uintptr(codepageID), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetConsoleCP.Addr(), uintptr(codepageID), 0, 0) if r1 == 0 { err = e1 } @@ -150,7 +150,7 @@ func SetConsoleCP(codepageID uint32) (err error) { } func SetConsoleOutputCP(codepageID uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetConsoleOutputCP.Addr(), 1, uintptr(codepageID), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetConsoleOutputCP.Addr(), uintptr(codepageID), 0, 0) if r1 == 0 { err = e1 } @@ -160,7 +160,3 @@ func SetConsoleOutputCP(codepageID uint32) (err error) { func staticTrue(f *os.File) bool { return true } - -func staticFalse(f *os.File) bool { - return false -}