Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ func completionImageNames(cmd *cobra.Command, _ []string, _ string) ([]string, c
var imageNames []string
if images, err := getImages(true); err == nil {
for _, image := range images {
if len(image.Names) != 1 {
if len(image.Names()) != 1 {
panic("cannot complete unflattened Image")
}

imageNames = append(imageNames, image.Names[0])
imageNames = append(imageNames, image.Names()[0])
}
}

Expand All @@ -149,12 +149,12 @@ func completionImageNamesFiltered(_ *cobra.Command, args []string, _ string) ([]
for _, image := range images {
skip := false

if len(image.Names) != 1 {
if len(image.Names()) != 1 {
panic("cannot complete unflattened Image")
}

for _, arg := range args {
if arg == image.Names[0] {
if arg == image.Names()[0] {
skip = true
break
}
Expand All @@ -164,7 +164,7 @@ func completionImageNamesFiltered(_ *cobra.Command, args []string, _ string) ([]
continue
}

imageNames = append(imageNames, image.Names[0])
imageNames = append(imageNames, image.Names()[0])
}
}

Expand Down
41 changes: 8 additions & 33 deletions src/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"os"
"sort"
"text/tabwriter"

"github.com/containers/toolbox/pkg/podman"
Expand All @@ -35,12 +34,6 @@ var (
onlyContainers bool
onlyImages bool
}

// toolboxLabels holds labels used by containers/images that mark them as compatible with Toolbx
toolboxLabels = map[string]string{
"com.github.debarshiray.toolbox": "true",
"com.github.containers.toolbox": "true",
}
)

var listCmd = &cobra.Command{
Expand Down Expand Up @@ -154,38 +147,20 @@ func listHelp(cmd *cobra.Command, args []string) {
func getImages(fillNameWithID bool) ([]podman.Image, error) {
logrus.Debug("Fetching all images")
var args []string
images, err := podman.GetImages(args...)
images, err := podman.GetImages(fillNameWithID, true, args...)
if err != nil {
logrus.Debugf("Fetching all images failed: %s", err)
return nil, errors.New("failed to get images")
}

processed := make(map[string]struct{})
var toolboxImages []podman.Image

for _, image := range images {
if _, ok := processed[image.ID]; ok {
continue
for images.Next() {
if image := images.Get(); image.IsToolbx() {
toolboxImages = append(toolboxImages, image)
}

processed[image.ID] = struct{}{}
var isToolboxImage bool

for label := range toolboxLabels {
if _, ok := image.Labels[label]; ok {
isToolboxImage = true
break
}
}

if isToolboxImage {
flattenedImages := image.FlattenNames(fillNameWithID)
toolboxImages = append(toolboxImages, flattenedImages...)
}

}

sort.Sort(podman.ImageSlice(toolboxImages))
return toolboxImages, nil
}

Expand All @@ -195,14 +170,14 @@ func listOutput(images []podman.Image, containers []podman.Container) {
fmt.Fprintf(writer, "%s\t%s\t%s\n", "IMAGE ID", "IMAGE NAME", "CREATED")

for _, image := range images {
if len(image.Names) != 1 {
if len(image.Names()) != 1 {
panic("cannot list unflattened Image")
}

fmt.Fprintf(writer, "%s\t%s\t%s\n",
utils.ShortID(image.ID),
image.Names[0],
image.Created)
utils.ShortID(image.ID()),
image.Names()[0],
image.Created())
}

writer.Flush()
Expand Down
12 changes: 9 additions & 3 deletions src/cmd/rmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func rmi(cmd *cobra.Command, args []string) error {
}

for _, image := range toolboxImages {
imageID := image.ID
imageID := image.ID()
if err := podman.RemoveImage(imageID, rmiFlags.forceDelete); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
continue
Expand All @@ -90,8 +90,14 @@ func rmi(cmd *cobra.Command, args []string) error {
}

for _, image := range args {
if _, err := podman.IsToolboxImage(image); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
imageObj, err := podman.InspectImage(image)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: failed to inspect image %s\n", image)
continue
}

if !imageObj.IsToolbx() {
fmt.Fprintf(os.Stderr, "Error: %s is not a Toolbx image\n", image)
continue
}

Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sources = files(
'pkg/nvidia/nvidia.go',
'pkg/podman/container.go',
'pkg/podman/errors.go',
'pkg/podman/image.go',
'pkg/podman/podman.go',
'pkg/podman/containerInspect_test.go',
'pkg/shell/shell.go',
Expand Down
Loading