Fix crash in older versions of Go.

It seems that some versions of the io package don't work well with nil
errors.

This change also replaces a link+remove with a single rename call.