def create_symlink_or_copy()

in aws_lambda_builders/utils.py [0:0]


def create_symlink_or_copy(source: str, destination: str) -> None:
    """Tries to create symlink, if it fails it will copy source into destination"""
    LOG.debug("Creating symlink; source: %s, destination: %s", source, destination)
    try:
        if Path(destination).exists() and Path(destination).is_symlink():
            # The symlink is already in place, don't try re-creating it
            LOG.debug("Symlink between %s and %s already exists, skipping generating symlink", source, destination)
            return
        os.symlink(Path(source).absolute(), Path(destination).absolute())
    except OSError as ex:
        LOG.warning(
            "Symbolic link creation failed, falling back to copying files instead. To optimize speed, "
            "consider enabling the necessary settings or privileges on your system to support symbolic links.",
            exc_info=ex if LOG.isEnabledFor(logging.DEBUG) else None,
        )
        copytree(source, destination)