Skip to content

Commit

Permalink
cmd/go/internal/lockedfile: ignore errors if locks are not supported
Browse files Browse the repository at this point in the history
Some file systems do not support file locking.
Ignore lock errors in these environments.
I used the already implemented IsNotSupported function.

If the file system does not support locking on Windows,
ERROR_INVALID_FUNCTION is returned.
Edited isNotSupported to ignore this.

References golang#37461
  • Loading branch information
kamijin-fanta committed Dec 4, 2020
1 parent cc386bd commit 5128edb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func unlock(f File) error {

func isNotSupported(err error) bool {
switch err {
case windows.ERROR_NOT_SUPPORTED, windows.ERROR_CALL_NOT_IMPLEMENTED, ErrNotSupported:
case windows.ERROR_INVALID_FUNCTION, windows.ERROR_NOT_SUPPORTED, windows.ERROR_CALL_NOT_IMPLEMENTED, ErrNotSupported:
return true
default:
return false
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/lockedfile/lockedfile_filelock.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func openFile(name string, flag int, perm fs.FileMode) (*os.File, error) {
default:
err = filelock.RLock(f)
}
if err != nil {
if err != nil && !filelock.IsNotSupported(err) {
f.Close()
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions src/internal/syscall/windows/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func UTF16PtrToString(p *uint16) string {
}

const (
ERROR_INVALID_FUNCTION syscall.Errno = 1
ERROR_SHARING_VIOLATION syscall.Errno = 32
ERROR_LOCK_VIOLATION syscall.Errno = 33
ERROR_NOT_SUPPORTED syscall.Errno = 50
Expand Down

0 comments on commit 5128edb

Please sign in to comment.