blob: ccb682281bc42b55ba7a7b142e0ae9f884b4fecf [file] [log] [blame]
package osutil
import (
"os"
"os/exec"
"syscall"
)
func Rename(src, dst string) error {
if err := os.Rename(src, dst); err != nil {
// Check if the rename operation failed
// because the source and destination are
// located on different mount points.
linkErr, ok := err.(*os.LinkError)
if !ok {
return err
}
errno, ok := linkErr.Err.(syscall.Errno)
if !ok || errno != syscall.EXDEV {
return err
}
// Fall back to a non-atomic rename.
cmd := exec.Command("mv", src, dst)
return cmd.Run()
}
return nil
}