forked from juju/testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
isnotexist_unix.go
27 lines (24 loc) · 864 Bytes
/
isnotexist_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
// +build !windows
package filetesting
import (
"os"
"syscall"
)
// isNotExist returns true if the error is consistent with an attempt to
// reference a file that does not exist. This works around the occasionally
// unhelpful behaviour of os.IsNotExist, which does not recognise the error
// produced when trying to read a path in which some component appears to
// reference a directory but actually references a file. For example, if
// "foo" is a file, an attempt to read "foo/bar" will generate an error that
// does not satisfy os.IsNotExist, but will satisfy filetesting.isNotExist.
func isNotExist(err error) bool {
if os.IsNotExist(err) {
return true
}
if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOTDIR {
return true
}
return false
}