(params: DockerResolverParameters | DockerCLIParameters, containerId: string | undefined, providedIdLabels: string[] | undefined, workspaceFolder: string | undefined, configFile: string | undefined, removeContainerWithOldLabels?: boolean | string)
| 714 | } |
| 715 | |
| 716 | export async function findContainerAndIdLabels(params: DockerResolverParameters | DockerCLIParameters, containerId: string | undefined, providedIdLabels: string[] | undefined, workspaceFolder: string | undefined, configFile: string | undefined, removeContainerWithOldLabels?: boolean | string) { |
| 717 | if (providedIdLabels) { |
| 718 | return { |
| 719 | container: containerId ? await inspectContainer(params, containerId) : await findDevContainer(params, providedIdLabels), |
| 720 | idLabels: providedIdLabels, |
| 721 | }; |
| 722 | } |
| 723 | |
| 724 | const normalizedWorkspaceFolder = workspaceFolder ? normalizeDevContainerLabelPath(process.platform, workspaceFolder) : workspaceFolder; |
| 725 | const normalizedConfigFile = configFile ? normalizeDevContainerLabelPath(process.platform, configFile) : configFile; |
| 726 | const oldLabels = [`${hostFolderLabel}=${normalizedWorkspaceFolder}`]; |
| 727 | const newLabels = [...oldLabels, `${configFileLabel}=${normalizedConfigFile}`]; |
| 728 | |
| 729 | let container: ContainerDetails | undefined; |
| 730 | if (containerId) { |
| 731 | container = await inspectContainer(params, containerId); |
| 732 | } else if (normalizedWorkspaceFolder && normalizedConfigFile) { |
| 733 | container = await findDevContainer(params, newLabels); |
| 734 | if (!container) { |
| 735 | container = await findDevContainerByNormalizedLabels(params, normalizedWorkspaceFolder, normalizedConfigFile); |
| 736 | } |
| 737 | if (!container) { |
| 738 | // Fall back to old labels. |
| 739 | container = await findDevContainer(params, oldLabels); |
| 740 | if (!container) { |
| 741 | container = await findLegacyDevContainerByNormalizedWorkspaceFolder(params, normalizedWorkspaceFolder); |
| 742 | } |
| 743 | if (container) { |
| 744 | if (container.Config.Labels?.[configFileLabel]) { |
| 745 | // But ignore containers with new labels. |
| 746 | container = undefined; |
| 747 | } else if (removeContainerWithOldLabels === true || removeContainerWithOldLabels === container.Id) { |
| 748 | // Remove container, so it will be rebuilt with new labels. |
| 749 | await removeContainer(params, container.Id); |
| 750 | container = undefined; |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | } else { |
| 755 | throw new Error(`Either containerId or workspaceFolder and configFile must be provided.`); |
| 756 | } |
| 757 | return { |
| 758 | container, |
| 759 | idLabels: !container || container.Config.Labels?.[configFileLabel] ? newLabels : oldLabels, |
| 760 | }; |
| 761 | } |
| 762 | |
| 763 | export function runAsyncHandler(handler: () => Promise<void>) { |
| 764 | (async () => { |
no test coverage detected