let move_in_same_device ?(if_exists=`Fail) ~src dst =
let real_dest = path_of_destination ~src ~dst in
begin match if_exists with
| `Fail ->
file_info real_dest
>>= begin function
| `Absent -> return ()
| _ -> fail (`System (`Move src, `File_exists real_dest))
end
| _ -> return ()
end
>>= fun () ->
Lwt.catch
Lwt.(fun () -> Lwt_unix.rename src real_dest >>= fun () -> return (`Ok `Moved))
begin function
| Unix.Unix_error (Unix.EXDEV, cmd, arg) -> return `Must_copy
| Unix.Unix_error (Unix.ENOTEMPTY, cmd, arg) -> return `Must_copy
| e -> fail (`System (`Move src, `Exn e))
end