From cfa309d8ce7e94440e0fc5e9887038b703bc3eb5 Mon Sep 17 00:00:00 2001 From: umohnani8 Date: Tue, 15 Aug 2017 15:02:43 -0400 Subject: [PATCH] Add functionality to pass the container name as argument also Initially 'kpod export' would only work if the full container ID was passed as the argument Now it works with a partial ID as well as container name Signed-off-by: umohnani8 --- cmd/kpod/export.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/kpod/export.go b/cmd/kpod/export.go index 53eb5080..f14190f7 100644 --- a/cmd/kpod/export.go +++ b/cmd/kpod/export.go @@ -77,19 +77,25 @@ func exportCmd(c *cli.Context) error { // exportContainer exports the contents of a container and saves it as // a tarball on disk func exportContainer(store storage.Store, opts exportOptions) error { - mountPoint, err := store.Mount(opts.container, "") + // gets the full container id when given a name or partial id + containerID, err := store.Lookup(opts.container) if err != nil { - return errors.Wrapf(err, "error finding container %q", opts.container) + return errors.Wrapf(err, "no such container %q", opts.container) + } + + mountPoint, err := store.Mount(containerID, "") + if err != nil { + return errors.Wrapf(err, "error finding container %q", containerID) } defer func() { - if err := store.Unmount(opts.container); err != nil { - fmt.Printf("error unmounting container %q: %v\n", opts.container, err) + if err := store.Unmount(containerID); err != nil { + fmt.Printf("error unmounting container %q: %v\n", containerID, err) } }() input, err := archive.Tar(mountPoint, archive.Uncompressed) if err != nil { - return errors.Wrapf(err, "error reading container directory %q", opts.container) + return errors.Wrapf(err, "error reading container directory %q", containerID) } outFile, err := os.Create(opts.output)