-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plan 9 doesn't have syscall.EAGAIN. Copy some code from Go's internal locakedfile package to check whether the file is locked by another process.
- Loading branch information
Showing
4 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package fslock | ||
|
||
import "strings" | ||
|
||
// Opening an exclusive-use file returns an error. | ||
// The expected error strings are: | ||
// | ||
// - "open/create -- file is locked" (cwfs, kfs) | ||
// - "exclusive lock" (fossil) | ||
// - "exclusive use file already open" (ramfs) | ||
// | ||
// See https://github.com/golang/go/blob/go1.15rc1/src/cmd/go/internal/lockedfile/lockedfile_plan9.go#L16 | ||
var lockedErrStrings = [...]string{ | ||
"file is locked", | ||
"exclusive lock", | ||
"exclusive use file already open", | ||
} | ||
|
||
// isLockedPlan9 return whether an os.OpenFile error indicates that | ||
// a file with the ModeExclusive bit set is already open. | ||
func isLockedPlan9(s string) bool { | ||
for _, frag := range lockedErrStrings { | ||
if strings.Contains(s, frag) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func lockedByOthers(err error) bool { | ||
s := err.Error() | ||
return strings.Contains(s, "Lock Create of") && isLockedPlan9(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// +build !plan9 | ||
|
||
package fslock | ||
|
||
import ( | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
func lockedByOthers(err error) bool { | ||
return err == syscall.EAGAIN || strings.Contains(err.Error(), "resource temporarily unavailable") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters