@@ -79,18 +79,22 @@ func Remove(ctx context.Context, client *containerd.Client, args []string, optio
79
79
80
80
if cid , ok := runningImages [found .Image .Name ]; ok {
81
81
if options .Force {
82
- // FIXME: this is suspicious, but passing the opt seem to break some tests
83
- // if err = is.Delete(ctx, found.Image.Name, delOpts...); err != nil {
84
- if err = is .Delete (ctx , found .Image .Name ); err != nil {
82
+ // This is a running image, so, we need to keep a ref on it so that containerd does not GC the layers
83
+ // First create the new image with an empty name
84
+ originalName := found .Image .Name
85
+ found .Image .Name = ":"
86
+ if _ , err = is .Create (ctx , found .Image ); err != nil {
85
87
return err
86
88
}
87
- fmt .Fprintf (options .Stdout , "Untagged: %s\n " , found .Image .Name )
88
- fmt .Fprintf (options .Stdout , "Untagged: %s\n " , found .Image .Target .Digest .String ())
89
89
90
- found . Image . Name = ":"
91
- if _ , err = is .Create (ctx , found . Image ); err != nil {
90
+ // Now, delete the original
91
+ if err = is .Delete (ctx , originalName , delOpts ... ); err != nil {
92
92
return err
93
93
}
94
+
95
+ fmt .Fprintf (options .Stdout , "Untagged: %s\n " , originalName )
96
+ fmt .Fprintf (options .Stdout , "Untagged: %s@%s\n " , originalName , found .Image .Target .Digest .String ())
97
+
94
98
return nil
95
99
}
96
100
return fmt .Errorf ("conflict: unable to delete %s (cannot be forced) - image is being used by running container %s" , found .Req , cid )
@@ -128,18 +132,22 @@ func Remove(ctx context.Context, client *containerd.Client, args []string, optio
128
132
129
133
if cid , ok := runningImages [found .Image .Name ]; ok {
130
134
if options .Force {
131
- // FIXME: this is suspicious, but passing the opt seem to break some tests
132
- // if err = is.Delete(ctx, found.Image.Name, delOpts...); err != nil {
133
- if err = is .Delete (ctx , found .Image .Name ); err != nil {
135
+ // This is a running image, so, we need to keep a ref on it so that containerd does not GC the layers
136
+ // First create the new image with an empty name
137
+ originalName := found .Image .Name
138
+ found .Image .Name = ":"
139
+ if _ , err = is .Create (ctx , found .Image ); err != nil {
134
140
return false , err
135
141
}
136
- fmt .Fprintf (options .Stdout , "Untagged: %s\n " , found .Image .Name )
137
- fmt .Fprintf (options .Stdout , "Untagged: %s\n " , found .Image .Target .Digest .String ())
138
142
139
- found . Image . Name = ":"
140
- if _ , err = is .Create (ctx , found . Image ); err != nil {
143
+ // Now, delete the original
144
+ if err = is .Delete (ctx , originalName , delOpts ... ); err != nil {
141
145
return false , err
142
146
}
147
+
148
+ fmt .Fprintf (options .Stdout , "Untagged: %s\n " , originalName )
149
+ fmt .Fprintf (options .Stdout , "Untagged: %s@%s\n " , originalName , found .Image .Target .Digest .String ())
150
+
143
151
return false , nil
144
152
}
145
153
return false , fmt .Errorf ("conflict: unable to delete %s (cannot be forced) - image is being used by running container %s" , found .Req , cid )
0 commit comments