From e72f000bde7dde447382c36403f084f47c97c7e8 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 12 Mar 2016 04:11:31 +0100 Subject: Simplify error handling --- cmd/acme/file.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'cmd') diff --git a/cmd/acme/file.go b/cmd/acme/file.go index ae2ade8..abd5a61 100644 --- a/cmd/acme/file.go +++ b/cmd/acme/file.go @@ -4,24 +4,15 @@ import ( "crypto" "crypto/tls" "crypto/x509" - "errors" "io" "os" "path" - "syscall" "dim13.org/acme" ) -var ErrNotFound = errors.New("file not found") - func NewFile(fname string, mode os.FileMode) (io.WriteCloser, error) { - err := os.Rename(fname, fname+".bak") - if err != nil { - if e, ok := err.(*os.LinkError); ok && e.Err != syscall.ENOENT { - return nil, err - } - } + _ = os.Rename(fname, fname+".bak") flags := os.O_WRONLY | os.O_CREATE | os.O_TRUNC return os.OpenFile(fname, flags, mode) } @@ -72,9 +63,6 @@ func (d domain) Save(cert tls.Certificate) error { func (d domain) Load() (tls.Certificate, error) { crt, err := tls.LoadX509KeyPair(d.CrtFile, d.KeyFile) if err != nil { - if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT { - err = ErrNotFound - } return tls.Certificate{}, err } crt.Leaf, err = x509.ParseCertificate(crt.Certificate[0]) @@ -96,9 +84,6 @@ func (a account) Save(key crypto.PrivateKey) error { func (a account) Load() (crypto.PrivateKey, error) { fd, err := os.Open(a.KeyFile) if err != nil { - if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT { - err = ErrNotFound - } return nil, err } defer fd.Close() -- cgit v1.2.3