Пример #1
0
def mark_repository_for_deletion(namespace_name, repository_name, repository_gc_queue):
    """
    Marks a repository for future deletion in the background.

    The repository will be renamed and hidden, and then deleted later by a worker.
    """
    repo = get_repository(namespace_name, repository_name)
    if not repo:
        return None

    with db_transaction():
        # Delete any stars for the repository.
        Star.delete().where(Star.repository == repo).execute()

        # Change the name and state of the repository.
        repo.name = str(uuid.uuid4())
        repo.state = RepositoryState.MARKED_FOR_DELETION
        repo.save()

        # Create a tracking row and a queueitem to delete the repository.
        marker = DeletedRepository.create(repository=repo, original_name=repository_name)

        # Add a queueitem to delete the repository.
        marker.queue_id = repository_gc_queue.put(
            [namespace_name, str(repo.id)],
            json.dumps({"marker_id": marker.id, "original_name": repository_name,}),
        )
        marker.save()

    # Run callbacks for the deleted repo.
    for callback in config.repo_cleanup_callbacks:
        callback(namespace_name, repository_name)

    return marker.id
Пример #2
0
def unstar_repository(user, repository):
    """ Unstars a repository. """
    try:
        (Star.delete().where(Star.repository == repository.id,
                             Star.user == user.id).execute())
    except Star.DoesNotExist:
        raise DataModelException("Star not found.")