Skip to content

Commit

Permalink
chore: simplify GOOS evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jun 30, 2024
1 parent d82685e commit 502c570
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions flock.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ 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" || runtime.GOOS == "solaris" || runtime.GOOS == "illumos" {
// AIX cannot preform write-lock (ie exclusive) on a
// read-only file.
switch runtime.GOOS {
case "aix", "solaris", "illumos":
// AIX cannot preform write-lock (i.e. exclusive) on a read-only file.
flags |= os.O_RDWR
} else {
default:
flags |= os.O_RDONLY
}

Expand Down
5 changes: 3 additions & 2 deletions flock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ func (s *TestSuite) TestFlock_TryRLock() {
locked, err = flock2.TryRLock()
s.Require().NoError(err)

if runtime.GOOS == "aix" || runtime.GOOS == "solaris" || runtime.GOOS == "illumos" {
switch runtime.GOOS {
case "aix", "solaris", "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
// would still be open but silently unlocked. So a second
// TryRLock must return false.
s.False(locked)
} else {
default:
s.True(locked)
}

Expand Down

0 comments on commit 502c570

Please sign in to comment.