static int s_profile_merge()

in source/aws_profile.c [545:581]


static int s_profile_merge(struct aws_profile *dest_profile, const struct aws_profile *source_profile) {

    AWS_ASSERT(dest_profile != NULL && source_profile != NULL);

    dest_profile->has_profile_prefix = source_profile->has_profile_prefix;

    struct aws_hash_iter source_iter = aws_hash_iter_begin(&source_profile->properties);
    while (!aws_hash_iter_done(&source_iter)) {
        struct aws_profile_property *source_property = (struct aws_profile_property *)source_iter.element.value;
        struct aws_profile_property *dest_property = (struct aws_profile_property *)aws_profile_get_property(
            dest_profile, (struct aws_string *)source_iter.element.key);
        if (dest_property == NULL) {

            struct aws_byte_cursor empty_value;
            AWS_ZERO_STRUCT(empty_value);

            struct aws_byte_cursor property_name = aws_byte_cursor_from_string(source_iter.element.key);
            dest_property = aws_profile_property_new(dest_profile->allocator, &property_name, &empty_value);
            if (dest_property == NULL) {
                return AWS_OP_ERR;
            }

            if (aws_hash_table_put(&dest_profile->properties, dest_property->name, dest_property, NULL)) {
                s_profile_property_destroy(dest_property);
                return AWS_OP_ERR;
            }
        }

        if (s_profile_property_merge(dest_property, source_property)) {
            return AWS_OP_ERR;
        }

        aws_hash_iter_next(&source_iter);
    }

    return AWS_OP_SUCCESS;
}