~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/testing/filetesting/isnotexist_unix.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

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