Commit 7c15b2ab authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

os: make IsExists also recognize syscall.ENOTEMPTY

And adds missing tests.

Fixes #14970

Change-Id: I0dba02603bc245f555498cb5dd3e0a9d87c52353
Reviewed-on: https://go-review.googlesource.com/21467Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 0656da91
......@@ -80,11 +80,13 @@ func checkErrorPredicate(predName string, pred func(error) bool, err error) stri
return ""
}
var isExistTests = []struct {
type isExistTest struct {
err error
is bool
isnot bool
}{
}
var isExistTests = []isExistTest{
{&os.PathError{Err: os.ErrInvalid}, false, false},
{&os.PathError{Err: os.ErrPermission}, false, false},
{&os.PathError{Err: os.ErrExist}, true, false},
......@@ -109,10 +111,12 @@ func TestIsExist(t *testing.T) {
}
}
var isPermissionTests = []struct {
type isPermissionTest struct {
err error
want bool
}{
}
var isPermissionTests = []isPermissionTest{
{nil, false},
{&os.PathError{Err: os.ErrPermission}, true},
{&os.SyscallError{Err: os.ErrPermission}, true},
......
......@@ -19,7 +19,7 @@ func isExist(err error) bool {
case *SyscallError:
err = pe.Err
}
return err == syscall.EEXIST || err == ErrExist
return err == syscall.EEXIST || err == syscall.ENOTEMPTY || err == ErrExist
}
func isNotExist(err error) bool {
......
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
package os_test
import (
"os"
"syscall"
)
func init() {
isExistTests = append(isExistTests,
isExistTest{err: &os.PathError{Err: syscall.EEXIST}, is: true, isnot: false},
isExistTest{err: &os.PathError{Err: syscall.ENOTEMPTY}, is: true, isnot: false},
isExistTest{err: &os.LinkError{Err: syscall.EEXIST}, is: true, isnot: false},
isExistTest{err: &os.LinkError{Err: syscall.ENOTEMPTY}, is: true, isnot: false},
isExistTest{err: &os.SyscallError{Err: syscall.EEXIST}, is: true, isnot: false},
isExistTest{err: &os.SyscallError{Err: syscall.ENOTEMPTY}, is: true, isnot: false},
)
isPermissionTests = append(isPermissionTests,
isPermissionTest{err: &os.PathError{Err: syscall.EACCES}, want: true},
isPermissionTest{err: &os.PathError{Err: syscall.EPERM}, want: true},
isPermissionTest{err: &os.PathError{Err: syscall.EEXIST}, want: false},
isPermissionTest{err: &os.LinkError{Err: syscall.EACCES}, want: true},
isPermissionTest{err: &os.LinkError{Err: syscall.EPERM}, want: true},
isPermissionTest{err: &os.LinkError{Err: syscall.EEXIST}, want: false},
isPermissionTest{err: &os.SyscallError{Err: syscall.EACCES}, want: true},
isPermissionTest{err: &os.SyscallError{Err: syscall.EPERM}, want: true},
isPermissionTest{err: &os.SyscallError{Err: syscall.EEXIST}, want: false},
)
}
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package os_test
import (
"os"
"syscall"
)
func init() {
const _ERROR_BAD_NETPATH = syscall.Errno(53)
isExistTests = append(isExistTests,
isExistTest{err: &os.PathError{Err: syscall.ERROR_FILE_NOT_FOUND}, is: false, isnot: true},
isExistTest{err: &os.LinkError{Err: syscall.ERROR_FILE_NOT_FOUND}, is: false, isnot: true},
isExistTest{err: &os.SyscallError{Err: syscall.ERROR_FILE_NOT_FOUND}, is: false, isnot: true},
isExistTest{err: &os.PathError{Err: _ERROR_BAD_NETPATH}, is: false, isnot: true},
isExistTest{err: &os.LinkError{Err: _ERROR_BAD_NETPATH}, is: false, isnot: true},
isExistTest{err: &os.SyscallError{Err: _ERROR_BAD_NETPATH}, is: false, isnot: true},
isExistTest{err: &os.PathError{Err: syscall.ERROR_PATH_NOT_FOUND}, is: false, isnot: true},
isExistTest{err: &os.LinkError{Err: syscall.ERROR_PATH_NOT_FOUND}, is: false, isnot: true},
isExistTest{err: &os.SyscallError{Err: syscall.ERROR_PATH_NOT_FOUND}, is: false, isnot: true},
)
isPermissionTests = append(isPermissionTests,
isPermissionTest{err: &os.PathError{Err: syscall.ERROR_ACCESS_DENIED}, want: true},
isPermissionTest{err: &os.LinkError{Err: syscall.ERROR_ACCESS_DENIED}, want: true},
isPermissionTest{err: &os.SyscallError{Err: syscall.ERROR_ACCESS_DENIED}, want: true},
)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment