Skip to content

Commit c527283

Browse files
authored
feat: use runtime errors instead of compilation errors for unusupported platforms (#85)
1 parent a0a31b7 commit c527283

7 files changed

+50
-2
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# - js/wasm
66
# - wasp1/wasm
77

8-
for row in $(go tool dist list -json | jq -r '.[] | select( .GOOS != "plan9" and .GOARCH != "wasm") | @base64'); do
8+
for row in $(go tool dist list -json | jq -r '.[] | @base64'); do
99
_jq() {
1010
echo ${row} | base64 --decode | jq -r ${1}
1111
}

flock_example_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Use of this source code is governed by the BSD 3-Clause
44
// license that can be found in the LICENSE file.
55

6+
//go:build !js && !plan9 && !wasip1
7+
68
package flock_test
79

810
import (

flock_internal_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Use of this source code is governed by the BSD 3-Clause
44
// license that can be found in the LICENSE file.
55

6+
//go:build !js && !plan9 && !wasip1
7+
68
package flock
79

810
import (

flock_others.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//go:build (!unix && !windows) || plan9
2+
3+
package flock
4+
5+
import (
6+
"errors"
7+
"io/fs"
8+
)
9+
10+
func (f *Flock) Lock() error {
11+
return &fs.PathError{
12+
Op: "Lock",
13+
Path: f.Path(),
14+
Err: errors.ErrUnsupported,
15+
}
16+
}
17+
18+
func (f *Flock) RLock() error {
19+
return &fs.PathError{
20+
Op: "RLock",
21+
Path: f.Path(),
22+
Err: errors.ErrUnsupported,
23+
}
24+
}
25+
26+
func (f *Flock) Unlock() error {
27+
return &fs.PathError{
28+
Op: "Unlock",
29+
Path: f.Path(),
30+
Err: errors.ErrUnsupported,
31+
}
32+
}
33+
34+
func (f *Flock) TryLock() (bool, error) {
35+
return false, f.Lock()
36+
}
37+
38+
func (f *Flock) TryRLock() (bool, error) {
39+
return false, f.RLock()
40+
}

flock_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Use of this source code is governed by the BSD 3-Clause
44
// license that can be found in the LICENSE file.
55

6+
//go:build !js && !plan9 && !wasip1
7+
68
package flock_test
79

810
import (

flock_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Use of this source code is governed by the BSD 3-Clause
44
// license that can be found in the LICENSE file.
55

6-
//go:build !aix && (!solaris || illumos) && !windows
6+
//go:build darwin || dragonfly || freebsd || illumos || linux || netbsd || openbsd
77

88
package flock
99

flock_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Use of this source code is governed by the BSD 3-Clause
44
// license that can be found in the LICENSE file.
55

6+
//go:build windows
7+
68
package flock
79

810
import (

0 commit comments

Comments
 (0)