static int s_profile_collection_merge()

in source/aws_profile.c [695:730]


static int s_profile_collection_merge(
    struct aws_profile_collection *dest_collection,
    const struct aws_profile_collection *source_collection) {

    AWS_ASSERT(dest_collection != NULL && source_collection);

    struct aws_hash_iter source_iter = aws_hash_iter_begin(&source_collection->profiles);
    while (!aws_hash_iter_done(&source_iter)) {
        struct aws_profile *source_profile = (struct aws_profile *)source_iter.element.value;
        struct aws_profile *dest_profile = (struct aws_profile *)aws_profile_collection_get_profile(
            dest_collection, (struct aws_string *)source_iter.element.key);

        if (dest_profile == NULL) {

            struct aws_byte_cursor name_cursor = aws_byte_cursor_from_string(source_iter.element.key);
            dest_profile =
                aws_profile_new(dest_collection->allocator, &name_cursor, source_profile->has_profile_prefix);
            if (dest_profile == NULL) {
                return AWS_OP_ERR;
            }

            if (aws_hash_table_put(&dest_collection->profiles, dest_profile->name, dest_profile, NULL)) {
                aws_profile_destroy(dest_profile);
                return AWS_OP_ERR;
            }
        }

        if (s_profile_merge(dest_profile, source_profile)) {
            return AWS_OP_ERR;
        }

        aws_hash_iter_next(&source_iter);
    }

    return AWS_OP_SUCCESS;
}