def METHOD_NAME(src, dst):
    """Attempts to hardlink ``src`` to ``dst``, copying if the link fails.
    Attempts to maintain the semantics of ``shutil.copy``.
    Because ``os.link`` does not overwrite files, a unique temporary file
    will be used if the target already exists, then that file will be moved
    into place.
    """
    if os.path.isdir(dst):
        dst = os.path.join(dst, os.path.basename(src))
    link_errno = link(src, dst)
    if link_errno == errno.EEXIST:
        if os.stat(src).st_ino == os.stat(dst).st_ino:
            # dst is already a hard link to the correct file, so we don't need
            # to do anything else. If we try to link and rename the file
            # anyway, we get duplicate files - see http://bugs.python.org/issue21876
            return
        new_dst = dst + "-temp-%04X" %(random.randint(1, 16**4), )
        try:
            METHOD_NAME(src, new_dst)
        except:
            try:
                os.remove(new_dst)
            except OSError:
                pass
            raise
        os.rename(new_dst, dst)
    elif link_errno != 0:
        # Either link isn't supported, or the filesystem doesn't support
        # linking, or 'src' and 'dst' are on different filesystems.
        shutil.copy(src, dst)