]> Cypherpunks repositories - gostls13.git/commitdiff
os: add some comments and remove an unused variable in rename func
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 18 May 2017 22:50:35 +0000 (22:50 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 18 May 2017 23:43:24 +0000 (23:43 +0000)
This slightly clarifies the just-submitted CL 40577.

Updates #19647

Change-Id: I5584ad0e1abbc31796e3e5752351857f2a13d6d7
Reviewed-on: https://go-review.googlesource.com/43625
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/os/file_unix.go

index f790b6e910dd75ecdf15278a9b29bbd4131ed5ca..7f5c84f4bdc5345ef973c30518e15ef943b1a542 100644 (file)
@@ -20,12 +20,14 @@ func fixLongPath(path string) string {
 func rename(oldname, newname string) error {
        fi, err := Lstat(newname)
        if err == nil && fi.IsDir() {
-               // if we cannot stat oldname we should
-               // return that error in favor of EEXIST
-               fi, err = Lstat(oldname)
-               if err != nil {
-                       if pErr, ok := err.(*PathError); ok {
-                               err = pErr.Err
+               // There are two independent errors this function can return:
+               // one for a bad oldname, and one for a bad newname.
+               // At this point we've determined the newname is bad.
+               // But just in case oldname is also bad, prioritize returning
+               // the oldname error because that's what we did historically.
+               if _, err := Lstat(oldname); err != nil {
+                       if pe, ok := err.(*PathError); ok {
+                               err = pe.Err
                        }
                        return &LinkError{"rename", oldname, newname, err}
                }