]> Cypherpunks repositories - gostls13.git/commitdiff
os: fix LinkError creation on windows.
authorHyang-Ah (Hana) Kim <hyangah@gmail.com>
Fri, 27 Feb 2015 17:34:25 +0000 (12:34 -0500)
committerHyang-Ah Hana Kim <hyangah@gmail.com>
Fri, 27 Feb 2015 23:31:36 +0000 (23:31 +0000)
Not only carrying invalid info but also this caused Error to crash with
null pointer exception.

Change-Id: Ibfe63d20eb9b9178ea618e59c74111e9245a6779
Reviewed-on: https://go-review.googlesource.com/6270
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/os/file_windows.go
src/os/os_test.go

index 2a90a50559d17615b5bb1f8bf8732c28df0d4b4f..fa0736753c857aaf8d13cca109d52ca5564ea268 100644 (file)
@@ -508,9 +508,8 @@ func Link(oldname, newname string) error {
        if err != nil {
                return &LinkError{"link", oldname, newname, err}
        }
-
-       e := syscall.CreateHardLink(n, o, 0)
-       if e != nil {
+       err = syscall.CreateHardLink(n, o, 0)
+       if err != nil {
                return &LinkError{"link", oldname, newname, err}
        }
        return nil
index 5285b760241fcbb3e530040aa195b81194eefb43..21d229635d23bf739fa4ea3675ae3c348ddbdd7f 100644 (file)
@@ -533,6 +533,14 @@ func TestHardLink(t *testing.T) {
        if err != nil {
                t.Fatalf("link %q, %q failed: %v", to, from, err)
        }
+
+       none := "hardlinktestnone"
+       err = Link(none, none)
+       // Check the returned error is well-formed.
+       if lerr, ok := err.(*LinkError); !ok || lerr.Error() == "" {
+               t.Errorf("link %q, %q failed to return a valid error", none, none)
+       }
+
        defer Remove(from)
        tostat, err := Stat(to)
        if err != nil {