Detect all containers that have been added or deleted from the specified container.
(containerName string)
| 943 | |
| 944 | // Detect all containers that have been added or deleted from the specified container. |
| 945 | func (m *manager) getContainersDiff(containerName string) (added []info.ContainerReference, removed []info.ContainerReference, err error) { |
| 946 | // Get all subcontainers recursively. |
| 947 | cont, ok := m.containers.Load(namespacedContainerName{Name: containerName}) |
| 948 | if !ok { |
| 949 | return nil, nil, fmt.Errorf("failed to find container %q while checking for new containers", containerName) |
| 950 | } |
| 951 | allContainers, err := cont.handler.ListContainers(container.ListRecursive) |
| 952 | |
| 953 | if err != nil { |
| 954 | return nil, nil, err |
| 955 | } |
| 956 | allContainers = append(allContainers, info.ContainerReference{Name: containerName}) |
| 957 | |
| 958 | // Determine which were added and which were removed. |
| 959 | allContainersSet := make(map[string]*containerData) |
| 960 | m.containers.Range(func(name namespacedContainerName, cont *containerData) bool { |
| 961 | if cont == nil { |
| 962 | return true |
| 963 | } |
| 964 | // Only add the canonical name. |
| 965 | if cont.info.Name == name.Name { |
| 966 | allContainersSet[name.Name] = cont |
| 967 | } |
| 968 | return true |
| 969 | }) |
| 970 | |
| 971 | // Added containers |
| 972 | for _, c := range allContainers { |
| 973 | delete(allContainersSet, c.Name) |
| 974 | _, ok := m.containers.Load(namespacedContainerName{Name: c.Name}) |
| 975 | if !ok { |
| 976 | added = append(added, c) |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | // Removed ones are no longer in the container listing. |
| 981 | for _, d := range allContainersSet { |
| 982 | removed = append(removed, d.info.ContainerReference) |
| 983 | } |
| 984 | |
| 985 | return |
| 986 | } |
| 987 | |
| 988 | // Detect the existing subcontainers and reflect the setup here. |
| 989 | func (m *manager) detectSubcontainers(containerName string) error { |
no test coverage detected