mirror of
https://github.com/golang/go
synced 2024-11-15 02:50:31 -07:00
[release-branch.go1] os: Rename error to fit IsExist
««« backport 104eb57df01b os: Rename error to fit IsExist Fixes #3828. R=golang-dev, iant, rsc CC=golang-dev https://golang.org/cl/6420056 »»»
This commit is contained in:
parent
bedafd2ddb
commit
6410538c72
@ -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
|
||||
}
|
||||
|
47
src/pkg/os/error_windows_test.go
Normal file
47
src/pkg/os/error_windows_test.go
Normal file
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user