~ubuntu-branches/ubuntu/trusty/juju-core/trusty-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/utils/file_unix.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-04-12 07:04:37 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20140412070437-jub6rry6bdr9rqw1
Tags: 1.18.1-0ubuntu1
* New upstream point release, including fixes for:
  - Upgrading juju 1.16.6 -> 1.18.x fails (LP: #1299802).
  - Peer relation disappears during juju-upgrade (LP: #1303697).
  - public-address of units changes to internal bridge post upgrade
    (LP: #1303735).
  - Unable to deploy local charms without series (LP: #1303880).
  - juju scp no longer allows multiple extra arguments to be passed
    (LP: #1306208).
  - juju cannot downgrade to same major.minor version with earlier
    patch number (LP: #1306296).

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
import (
8
8
        "os"
 
9
        "syscall"
9
10
)
10
11
 
11
12
// ReplaceFile atomically replaces the destination file or directory
14
15
func ReplaceFile(source, destination string) error {
15
16
        return os.Rename(source, destination)
16
17
}
 
18
 
 
19
// IsNotExist returns true if the error is consistent with an attempt to
 
20
// reference a file that does not exist. This works around the occasionally
 
21
// unhelpful behaviour of os.IsNotExist, which does not recognise the error
 
22
// produced when trying to read a path in which some component appears to
 
23
// reference a directory but actually references a file. For example, if
 
24
// "foo" is a file, an attempt to read "foo/bar" will generate an error that
 
25
// does not satisfy os.IsNotExist, but will satisfy utils.IsNotExist.
 
26
func IsNotExist(err error) bool {
 
27
        if os.IsNotExist(err) {
 
28
                return true
 
29
        }
 
30
        if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOTDIR {
 
31
                return true
 
32
        }
 
33
        return false
 
34
}