Hi everyone,
I was coding a program that uses os.Rename(oldFile, newFile) and I get an error saying invalid cross-device link when oldFile and newFile are in different partitions.Is that expected or is it a bug? Why that happens?
Thank you
Did you find any solution ? I'm having the exact similar issue.
func customRename(prevPath, newPath string, mode os.FileMode) error {
err := os.Rename(prevPath, newPath) if err != nil {
byteArr, err2 := ioutil.ReadFile(prevPath) if err2 != nil { return err2 }
err2 = ioutil.WriteFile(newPath, byteArr, mode) if err2 == nil { // Remove the file iff it was able to be written _ = os.Remove(prevPath) } else { log.Printf("unable to write the file out to the new path. Previous: %s --> New: %s\n", prevPath, newPath) // Remove any partial file data that may have been written in the case of unfulfilled writes. _ = os.Remove(newPath) }
return err2 } return err}
--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.