From 6410538c72b8c179e4c14f62ed87024f0f4f8634 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Sat, 22 Sep 2012 05:54:23 +1000 Subject: [PATCH] [release-branch.go1] os: Rename error to fit IsExist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ««« backport 104eb57df01b os: Rename error to fit IsExist Fixes #3828. R=golang-dev, iant, rsc CC=golang-dev https://golang.org/cl/6420056 »»» --- src/pkg/os/error_windows.go | 3 ++ src/pkg/os/error_windows_test.go | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/pkg/os/error_windows_test.go diff --git a/src/pkg/os/error_windows.go b/src/pkg/os/error_windows.go index fbb0d4f3fe..2562485726 100644 --- a/src/pkg/os/error_windows.go +++ b/src/pkg/os/error_windows.go @@ -10,6 +10,9 @@ func isExist(err error) bool { if pe, ok := err.(*PathError); ok { err = pe.Err } + if pe, ok := err.(*LinkError); ok { + err = pe.Err + } return err == syscall.ERROR_ALREADY_EXISTS || err == syscall.ERROR_FILE_EXISTS || err == ErrExist } diff --git a/src/pkg/os/error_windows_test.go b/src/pkg/os/error_windows_test.go new file mode 100644 index 0000000000..3e6504f8db --- /dev/null +++ b/src/pkg/os/error_windows_test.go @@ -0,0 +1,47 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package os_test + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" +) + +func TestErrIsExistAfterRename(t *testing.T) { + dir, err := ioutil.TempDir("", "go-build") + if err != nil { + t.Fatalf("Create temp directory: %v", err) + } + defer os.RemoveAll(dir) + + src := filepath.Join(dir, "src") + dest := filepath.Join(dir, "dest") + + f, err := os.Create(src) + if err != nil { + t.Fatalf("Create file %v: %v", src, err) + } + f.Close() + err = os.Rename(src, dest) + if err != nil { + t.Fatalf("Rename %v to %v: %v", src, dest, err) + } + + f, err = os.Create(src) + if err != nil { + t.Fatalf("Create file %v: %v", src, err) + } + f.Close() + err = os.Rename(src, dest) + if err == nil { + t.Fatal("Rename should have failed") + } + if s := checkErrorPredicate("os.IsExist", os.IsExist, err); s != "" { + t.Fatal(s) + return + } +}