Skip to content

Commit

Permalink
feat: use runtime errors instead of compilation errors for unusupport…
Browse files Browse the repository at this point in the history
…ed platforms (#85)
  • Loading branch information
ldez committed Jul 2, 2024
1 parent a0a31b7 commit c527283
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# - js/wasm
# - wasp1/wasm

for row in $(go tool dist list -json | jq -r '.[] | select( .GOOS != "plan9" and .GOARCH != "wasm") | @base64'); do
for row in $(go tool dist list -json | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
Expand Down
2 changes: 2 additions & 0 deletions flock_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Use of this source code is governed by the BSD 3-Clause
// license that can be found in the LICENSE file.

//go:build !js && !plan9 && !wasip1

package flock_test

import (
Expand Down
2 changes: 2 additions & 0 deletions flock_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Use of this source code is governed by the BSD 3-Clause
// license that can be found in the LICENSE file.

//go:build !js && !plan9 && !wasip1

package flock

import (
Expand Down
40 changes: 40 additions & 0 deletions flock_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//go:build (!unix && !windows) || plan9

package flock

import (
"errors"
"io/fs"
)

func (f *Flock) Lock() error {
return &fs.PathError{
Op: "Lock",
Path: f.Path(),
Err: errors.ErrUnsupported,
}
}

func (f *Flock) RLock() error {
return &fs.PathError{
Op: "RLock",
Path: f.Path(),
Err: errors.ErrUnsupported,
}
}

func (f *Flock) Unlock() error {
return &fs.PathError{
Op: "Unlock",
Path: f.Path(),
Err: errors.ErrUnsupported,
}
}

func (f *Flock) TryLock() (bool, error) {
return false, f.Lock()
}

func (f *Flock) TryRLock() (bool, error) {
return false, f.RLock()
}
2 changes: 2 additions & 0 deletions flock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Use of this source code is governed by the BSD 3-Clause
// license that can be found in the LICENSE file.

//go:build !js && !plan9 && !wasip1

package flock_test

import (
Expand Down
2 changes: 1 addition & 1 deletion flock_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (!solaris || illumos) && !windows
//go:build darwin || dragonfly || freebsd || illumos || linux || netbsd || openbsd

package flock

Expand Down
2 changes: 2 additions & 0 deletions flock_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Use of this source code is governed by the BSD 3-Clause
// license that can be found in the LICENSE file.

//go:build windows

package flock

import (
Expand Down

0 comments on commit c527283

Please sign in to comment.