MCPcopy Create free account
hub / github.com/containers/common / Save

Method Save

libimage/save.go:35–72  ·  view source on GitHub ↗

Save saves one or more images indicated by `names` in the specified `format` to `path`. Supported formats are oci-archive, docker-archive, oci-dir and docker-dir. The latter two adhere to the dir transport in the corresponding oci or docker v2s2 format. Please note that only docker-archive suppor

(ctx context.Context, names []string, format, path string, options *SaveOptions)

Source from the content-addressed store, hash-verified

33// saving more than one images. Other formats will yield an error attempting
34// to save more than one.
35func (r *Runtime) Save(ctx context.Context, names []string, format, path string, options *SaveOptions) error {
36 logrus.Debugf("Saving one more images (%s) to %q", names, path)
37
38 if options == nil {
39 options = &SaveOptions{}
40 }
41
42 // First some sanity checks to simplify subsequent code.
43 switch len(names) {
44 case 0:
45 return errors.New("no image specified for saving images")
46 case 1:
47 // All formats support saving 1.
48 default:
49 if format != "docker-archive" {
50 return errors.Errorf("unsupported format %q for saving multiple images (only docker-archive)", format)
51 }
52 if len(options.AdditionalTags) > 0 {
53 return errors.Errorf("cannot save multiple images with multiple tags")
54 }
55 }
56
57 // Dispatch the save operations.
58 switch format {
59 case "oci-archive", "oci-dir", "docker-dir":
60 if len(names) > 1 {
61 return errors.Errorf("%q does not support saving multiple images (%v)", format, names)
62 }
63 return r.saveSingleImage(ctx, names[0], format, path, options)
64
65 case "docker-archive":
66 options.ManifestMIMEType = manifest.DockerV2Schema2MediaType
67 return r.saveDockerArchive(ctx, names, path, options)
68 }
69
70 return errors.Errorf("unsupported format %q for saving images", format)
71
72}
73
74// saveSingleImage saves the specified image name to the specified path.
75// Supported formats are "oci-archive", "oci-dir" and "docker-dir".

Callers 1

TestSaveFunction · 0.80

Calls 2

saveSingleImageMethod · 0.95
saveDockerArchiveMethod · 0.95

Tested by 1

TestSaveFunction · 0.64