Commit ca598e3c authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

os: add some comments and remove an unused variable in rename func

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: 's avatarIan Lance Taylor <iant@golang.org>
parent 2ad41a30
...@@ -20,12 +20,14 @@ func fixLongPath(path string) string { ...@@ -20,12 +20,14 @@ func fixLongPath(path string) string {
func rename(oldname, newname string) error { func rename(oldname, newname string) error {
fi, err := Lstat(newname) fi, err := Lstat(newname)
if err == nil && fi.IsDir() { if err == nil && fi.IsDir() {
// if we cannot stat oldname we should // There are two independent errors this function can return:
// return that error in favor of EEXIST // one for a bad oldname, and one for a bad newname.
fi, err = Lstat(oldname) // At this point we've determined the newname is bad.
if err != nil { // But just in case oldname is also bad, prioritize returning
if pErr, ok := err.(*PathError); ok { // the oldname error because that's what we did historically.
err = pErr.Err if _, err := Lstat(oldname); err != nil {
if pe, ok := err.(*PathError); ok {
err = pe.Err
} }
return &LinkError{"rename", oldname, newname, err} return &LinkError{"rename", oldname, newname, err}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment