From d82685ef405f0f236e415b58a37f5600e2ed8fe2 Mon Sep 17 00:00:00 2001 From: Gaige B Paulsen Date: Sat, 29 Jun 2024 08:42:06 -0400 Subject: [PATCH] feat: add support for Illumos/Solaris (#63) --- build.sh | 3 +-- flock.go | 2 +- flock_test.go | 2 +- flock_unix.go | 2 +- flock_aix.go => flock_unix_variants.go | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) rename flock_aix.go => flock_unix_variants.go (99%) diff --git a/build.sh b/build.sh index b644f21..34d3a9c 100755 --- a/build.sh +++ b/build.sh @@ -2,11 +2,10 @@ # Not supported by flock: # - plan9/* -# - solaris/* # - js/wasm # - wasp1/wasm -for row in $(go tool dist list -json | jq -r '.[] | select( .GOOS != "plan9" and .GOOS != "solaris" and .GOARCH != "wasm") | @base64'); do +for row in $(go tool dist list -json | jq -r '.[] | select( .GOOS != "plan9" and .GOARCH != "wasm") | @base64'); do _jq() { echo ${row} | base64 --decode | jq -r ${1} } diff --git a/flock.go b/flock.go index 3c694f9..97ba857 100644 --- a/flock.go +++ b/flock.go @@ -119,7 +119,7 @@ func (f *Flock) setFh() error { // open a new os.File instance // create it if it doesn't exist, and open the file read-only. flags := os.O_CREATE - if runtime.GOOS == "aix" { + if runtime.GOOS == "aix" || runtime.GOOS == "solaris" || runtime.GOOS == "illumos" { // AIX cannot preform write-lock (ie exclusive) on a // read-only file. flags |= os.O_RDWR diff --git a/flock_test.go b/flock_test.go index 82e0dd8..bee84ea 100644 --- a/flock_test.go +++ b/flock_test.go @@ -119,7 +119,7 @@ func (s *TestSuite) TestFlock_TryRLock() { locked, err = flock2.TryRLock() s.Require().NoError(err) - if runtime.GOOS == "aix" { + if runtime.GOOS == "aix" || runtime.GOOS == "solaris" || runtime.GOOS == "illumos" { // When using POSIX locks, we can't safely read-lock the same // inode through two different descriptors at the same time: // when the first descriptor is closed, the second descriptor diff --git a/flock_unix.go b/flock_unix.go index f5f17f4..4fde9f0 100644 --- a/flock_unix.go +++ b/flock_unix.go @@ -3,7 +3,7 @@ // Use of this source code is governed by the BSD 3-Clause // license that can be found in the LICENSE file. -//go:build !aix && !windows +//go:build !aix && !solaris && !windows package flock diff --git a/flock_aix.go b/flock_unix_variants.go similarity index 99% rename from flock_aix.go rename to flock_unix_variants.go index 134a4a0..e485e16 100644 --- a/flock_aix.go +++ b/flock_unix_variants.go @@ -15,7 +15,7 @@ // This code is adapted from the Go package: // cmd/go/internal/lockedfile/internal/filelock -//go:build aix +//go:build aix || solaris package flock