#!/bin/bash

dockerSwitcherUpdateContainersToDockerType()
{
    # Called mid-switch (new daemon up, BEFORE reconcileDockerOwnership), so
    # containers/ is still owned by the OLD mode's container user. Enumerate as
    # that user — containers/ isn't list-readable by the manager under rootless,
    # and CFG is already the TARGET mode — by flipping CFG to old_mode just for
    # the find, then restoring it so the per-app socket scan + restart below talk
    # to the NEW daemon. (The two former rooted/rootless branches were identical.)
    local old_mode="$1"

    local saved_type="$CFG_DOCKER_INSTALL_TYPE"
    if [[ -n "$old_mode" ]]; then
        CFG_DOCKER_INSTALL_TYPE="$old_mode"
        resolveDockerInstallUser
    fi
    local subdirectories=($(runFileOp find "$containers_dir" -maxdepth 1 -type d))
    CFG_DOCKER_INSTALL_TYPE="$saved_type"
    resolveDockerInstallUser

    for dir in "${subdirectories[@]}"; do
        dockerSwitcherScanContainersForSocket "$dir"
        if [[ $docker_socket_file_updated == "true" ]]; then
            dockerRestartAppViaInstall $(basename $dir);
        fi
        docker_socket_file_updated="false"
    done
}
