func SafeMove(src, dst string) error {
	err := os.Rename(src, dst)

	if err != nil {
		in, err := os.Open(src)
		if err != nil {
			return err
		}
		defer in.Close()

		out, err := os.Create(dst)
		if err != nil {
			return err
		}
		defer out.Close()

		_, err = io.Copy(out, in)
		if err != nil {
			return err
		}

		err = out.Close()
		if err != nil {
			return err
		}

		err = os.Remove(src)
		if err != nil {
			return err
		}
	}

	return nil
}
// SafeMove attempts to move the file with path src to dest using os.Rename. If this fails, then it copies src to dest, then deletes src.
SafeMove attempts to move the file with path src to dest using os.Rename. If this fails, then it copies src to dest, then deletes src.
// SafeMove attempts to move the file with path src to dest using os . Rename . If this fails then it copies src to dest then deletes src .
func SafeMove(src, dst string) error {
	err := os.Rename(src, dst)
	if err != nil {
		in, err := os.Open(src)
		if err != nil {
			return err
		}
		defer in.Close()
		out, err := os.Create(dst)
		if err != nil {
			return err
		}
		defer out.Close()
		_, err = io.Copy(out, in)
		if err != nil {
			return err
		}
		err = out.Close()
		if err != nil {
			return err
		}
		err = os.Remove(src)
		if err != nil {
			return err
		}
	}
	return nil
}
func SafeMove ( src , dst string ) error { err := os . Rename ( src , dst ) if err != nil { in , err := os . Open ( src ) if err != nil { return err } defer in . Close ( ) out , err := os . Create ( dst ) if err != nil { return err } defer out . Close ( ) _ , err = io . Copy ( out , in ) if err != nil { return err } err = out . Close ( ) if err != nil { return err } err = os . Remove ( src ) if err != nil { return err } } return nil }
SafeMove attempts to move the file with path src to dest using os.Rename.
SafeMove attempts to move the file with path src to dest using os . Rename .