# docker_cp_file
# --------------
# Copia un archivo local a un contenedor Docker y verifica que el tamaño coincide.
# Imprime JSON con local_size y remote_size a stdout si la copia es exitosa.
# Sale con exit code 1 si docker cp falla o si los tamaños no coinciden.
#
# USO (sourced):
#   source docker_cp_file.sh
#   result=$(docker_cp_file /ruta/local.db metabase /dest/path.db)

docker_cp_file() {
    local local_path="$1"
    local container_name="$2"
    local dest_path="$3"

    if ! docker cp "$local_path" "${container_name}:${dest_path}" 2>/dev/null; then
        echo "docker_cp_file: fallo al copiar '$local_path' a '${container_name}:${dest_path}'" >&2
        return 1
    fi

    local local_size
    local_size=$(stat -c%s "$local_path")

    local remote_size
    remote_size=$(docker exec "$container_name" stat -c%s "$dest_path" 2>/dev/null || echo "-1")

    if [ "$local_size" != "$remote_size" ]; then
        echo "docker_cp_file: tamaños no coinciden (local=${local_size}, remoto=${remote_size})" >&2
        return 1
    fi

    printf '{"local_size":%s,"remote_size":%s}' "$local_size" "$remote_size"
}
