diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_api.go | 11 | ||||
-rw-r--r-- | libpod/runtime_img.go | 24 |
2 files changed, 19 insertions, 16 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go index 38c3faeef..253428256 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -9,6 +9,7 @@ import ( "strconv" "time" + "github.com/containers/storage" "github.com/docker/docker/daemon/caps" "github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/stringid" @@ -588,19 +589,19 @@ func (c *Container) Inspect(size bool) (*inspect.ContainerInspectData, error) { // Commit commits the changes between a container and its image, creating a new // image -func (c *Container) Commit(pause bool, options CopyOptions) error { +func (c *Container) Commit(pause bool, options CopyOptions) (*storage.Image, error) { if !c.locked { c.lock.Lock() defer c.lock.Unlock() if err := c.syncContainer(); err != nil { - return err + return nil, err } } if c.state.State == ContainerStateRunning && pause { if err := c.runtime.ociRuntime.pauseContainer(c); err != nil { - return errors.Wrapf(err, "error pausing container %q", c.ID()) + return nil, errors.Wrapf(err, "error pausing container %q", c.ID()) } defer func() { if err := c.runtime.ociRuntime.unpauseContainer(c); err != nil { @@ -611,13 +612,13 @@ func (c *Container) Commit(pause bool, options CopyOptions) error { tempFile, err := ioutil.TempFile(c.runtime.config.TmpDir, "podman-commit") if err != nil { - return errors.Wrapf(err, "error creating temp file") + return nil, errors.Wrapf(err, "error creating temp file") } defer os.Remove(tempFile.Name()) defer tempFile.Close() if err := c.export(tempFile.Name()); err != nil { - return err + return nil, err } return c.runtime.ImportImage(tempFile.Name(), options) } diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go index 8a21785bf..bc328d5b9 100644 --- a/libpod/runtime_img.go +++ b/libpod/runtime_img.go @@ -1032,30 +1032,30 @@ func (r *Runtime) GetHistory(image string) ([]ociv1.History, []types.BlobInfo, s } // ImportImage imports an OCI format image archive into storage as an image -func (r *Runtime) ImportImage(path string, options CopyOptions) error { +func (r *Runtime) ImportImage(path string, options CopyOptions) (*storage.Image, error) { r.lock.RLock() defer r.lock.RUnlock() if !r.valid { - return ErrRuntimeStopped + return nil, ErrRuntimeStopped } file := TarballTransport + ":" + path src, err := alltransports.ParseImageName(file) if err != nil { - return errors.Wrapf(err, "error parsing image name %q", path) + return nil, errors.Wrapf(err, "error parsing image name %q", path) } updater, ok := src.(tarball.ConfigUpdater) if !ok { - return errors.Wrapf(err, "unexpected type, a tarball reference should implement tarball.ConfigUpdater") + return nil, errors.Wrapf(err, "unexpected type, a tarball reference should implement tarball.ConfigUpdater") } annotations := make(map[string]string) err = updater.ConfigUpdate(options.ImageConfig, annotations) if err != nil { - return errors.Wrapf(err, "error updating image config") + return nil, errors.Wrapf(err, "error updating image config") } var reference = options.Reference @@ -1065,24 +1065,26 @@ func (r *Runtime) ImportImage(path string, options CopyOptions) error { if reference == "" { reference, err = getImageDigest(src, sc) if err != nil { - return err + return nil, err } } policyContext, err := getPolicyContext(sc) if err != nil { - return err + return nil, err } defer policyContext.Destroy() - - copyOptions := common.GetCopyOptions(os.Stdout, "", nil, nil, common.SigningOptions{}, "", "", false) + copyOptions := common.GetCopyOptions(options.Writer, "", nil, nil, common.SigningOptions{}, "", "", false) dest, err := is.Transport.ParseStoreReference(r.store, reference) if err != nil { errors.Wrapf(err, "error getting image reference for %q", options.Reference) } - - return cp.Image(policyContext, dest, src, copyOptions) + if err = cp.Image(policyContext, dest, src, copyOptions); err != nil { + return nil, err + } + // Use no lock version of GetImage + return r.getImage(reference) } // GetImageInspectInfo returns the inspect information of an image |