Skip to content

Commit

Permalink
fix: remove image tag only not the image using id
Browse files Browse the repository at this point in the history
This fix:
* switches to use name:tag to delete image
* run delete commands as a chain to avoid conflicts when
  deleting different tags of the same image

Fix containers#2673

Signed-off-by: Denis Golovin <dgolovin@redhat.com>
  • Loading branch information
dgolovin committed Sep 8, 2023
1 parent 16eba36 commit 307e79c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 28 deletions.
21 changes: 7 additions & 14 deletions packages/renderer/src/lib/ImagesList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,14 @@ function toggleAllImages(checked: boolean) {
// delete the items selected in the list
let bulkDeleteInProgress = false;
async function deleteSelectedImages() {
bulkDeleteInProgress = true;
const selectedImages = images.filter(image => image.selected);
if (selectedImages.length > 0) {
bulkDeleteInProgress = true;
await Promise.all(
selectedImages.map(async image => {
try {
await window.deleteImage(image.engineId, image.id);
} catch (e) {
console.log('error while removing image', e);
}
}),
);
bulkDeleteInProgress = false;
}
await selectedImages.reduce((prev: Promise<void>, image) => {
return prev
.then(() => window.deleteImage(image.engineId, `${image.name}:${image.tag}`))
.catch((e: unknown) => console.log('error while removing image', e));
}, Promise.resolve());
bulkDeleteInProgress = false;
}
let refreshTimeouts: NodeJS.Timeout[] = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/src/lib/image/ImageActions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $: window.hasAuthconfigForImage(image.name).then(result => (isAuthenticatedForTh
async function deleteImage(): Promise<void> {
try {
await window.deleteImage(image.engineId, image.id);
await window.deleteImage(image.engineId, `${image.name}:${image.tag}`);
} catch (error) {
errorTitle = 'Error while deleting image';
errorMessage = String(error);
Expand Down
12 changes: 5 additions & 7 deletions packages/renderer/src/lib/image/ImageDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ onMount(() => {
return imagesInfos.subscribe(images => {
const matchingImage = images.find(c => c.Id === imageID && c.engineId === engineId);
if (matchingImage) {
try {
image = imageUtils.getImageInfoUI(matchingImage, base64RepoTag);
} catch (err) {
console.error(err);
const tempImage = imageUtils.getImageInfoUI(matchingImage, base64RepoTag);
if (tempImage) {
image = tempImage;
return;
}
} else if (detailsPage) {
// the image has been deleted
detailsPage.close();
}
detailsPage.close();
});
});
</script>
Expand Down
8 changes: 2 additions & 6 deletions packages/renderer/src/lib/image/image-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,8 @@ export class ImageUtils {
}
}

getImageInfoUI(imageInfo: ImageInfo, base64RepoTag: string): ImageInfoUI {
getImageInfoUI(imageInfo: ImageInfo, base64RepoTag: string): ImageInfoUI | undefined {
const images = this.getImagesInfoUI(imageInfo, []);
const matchingImages = images.filter(image => image.base64RepoTag === base64RepoTag);
if (matchingImages.length === 1) {
return matchingImages[0];
}
throw new Error(`Unable to find a matching image for id ${imageInfo.Id} and tag ${base64RepoTag}`);
return images.find(image => image.base64RepoTag === base64RepoTag);
}
}

0 comments on commit 307e79c

Please sign in to comment.