diff options
author | Rob Pike <r@golang.org> | 2012-02-17 10:04:29 +1100 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2012-02-17 10:04:29 +1100 |
commit | 56069f0333ea5464a5d6688c55a03b607b01ad11 (patch) | |
tree | 40efb83a8aa6363893e04efeaf37dbeaf0ccfaf0 /doc/go1.html | |
parent | c560a0742b2b91d6cb7bb890cf33d55beb68680d (diff) | |
download | go-git-56069f0333ea5464a5d6688c55a03b607b01ad11.tar.gz |
os: delete os.EINVAL and so on
The set of errors forwarded by the os package varied with system and
was therefore non-portable.
Three helpers added for portable error checking: IsExist, IsNotExist, and IsPermission.
One or two more may need to come, but let's keep the set very small to discourage
thinking about errors that way.
R=mikioh.mikioh, gustavo, r, rsc
CC=golang-dev
https://golang.org/cl/5672047
Diffstat (limited to 'doc/go1.html')
-rw-r--r-- | doc/go1.html | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/doc/go1.html b/doc/go1.html index b1f92338da..13d74012bc 100644 --- a/doc/go1.html +++ b/doc/go1.html @@ -1494,12 +1494,31 @@ the i-number expression could be contracted to The vast majority of uses of <code>FileInfo</code> need only the methods of the standard interface. </p> - + +<p> +The <code>os</code> package no longer contains wrappers for the POSIX errors +such as <code>ENOENT</code>. +For the few programs that need to verify particular error conditions, there are +now the boolean functions +<a href="/pkg/os/#IsExist"><code>IsExist</code></a>, +<a href="/pkg/os/#IsNotExist"><code>IsNotExist</code></a> +and +<a href="/pkg/os/#IsPermission"><code>IsPermission</code></a>. +</p> + +<pre><!--{{code "progs/go1.go" `/os\.Open/` `/}/`}} +--> f, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) + if os.IsExist(err) { + log.Printf("%s already exists", name) + }</pre> + <p> <em>Updating</em>: Running <code>go fix</code> will update code that uses the old equivalent of the current <code>os.FileInfo</code> and <code>os.FileMode</code> API. Code that needs system-specific file details will need to be updated by hand. +Code that uses the old POSIX error values from the <code>os</code> package +will fail to compile and will also need to be updated by hand. </p> <h3 id="path_filepath">The path/filepath package</h3> |