From cc983be17a9ed00dfb4296767c9e16dee7f19181 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Thu, 30 Mar 2017 17:20:16 -0700 Subject: [PATCH] cmd/dist, images: allow image delete This adds very simple deletion of images by name. We still need to consider the approach to handling image name, so this may change. For the time being, it allows one to delete an image entry in the metadata database. Signed-off-by: Stephen J Day --- cmd/dist/images.go | 38 ++++++++++++++++++++++++++++++++++++++ cmd/dist/main.go | 1 + cmd/dist/pull.go | 1 + images/storage.go | 6 ++++++ 4 files changed, 46 insertions(+) diff --git a/cmd/dist/images.go b/cmd/dist/images.go index be5a83d7f..fbc1e76c1 100644 --- a/cmd/dist/images.go +++ b/cmd/dist/images.go @@ -61,3 +61,41 @@ var imagesCommand = cli.Command{ return nil }, } + +var rmiCommand = cli.Command{ + Name: "rmi", + Usage: "Delete one or more images by reference.", + ArgsUsage: "[flags] [, ...]", + Description: `Delete one or more images by reference.`, + Flags: []cli.Flag{}, + Action: func(clicontext *cli.Context) error { + var ( + ctx = background + exitErr error + ) + + db, err := getDB(clicontext, false) + if err != nil { + return errors.Wrap(err, "failed to open database") + } + + tx, err := db.Begin(true) + if err != nil { + return errors.Wrap(err, "could not start transaction") + } + defer tx.Rollback() + + for _, target := range clicontext.Args() { + if err := images.Delete(tx, target); err != nil { + if exitErr == nil { + exitErr = errors.Wrapf(err, "unable to delete %v", target) + } + log.G(ctx).WithError(err).Errorf("unable to delete %v", target) + } + + fmt.Println(target) + } + + return exitErr + }, +} diff --git a/cmd/dist/main.go b/cmd/dist/main.go index d0070cff2..c3fc54edf 100644 --- a/cmd/dist/main.go +++ b/cmd/dist/main.go @@ -62,6 +62,7 @@ distribution tool } app.Commands = []cli.Command{ imagesCommand, + rmiCommand, pullCommand, fetchCommand, fetchObjectCommand, diff --git a/cmd/dist/pull.go b/cmd/dist/pull.go index 1c93f251e..82423f8ec 100644 --- a/cmd/dist/pull.go +++ b/cmd/dist/pull.go @@ -67,6 +67,7 @@ command. As part of this process, we do the following: ingester := contentservice.NewIngesterFromClient(contentapi.NewContentClient(conn)) provider := contentservice.NewProviderFromClient(contentapi.NewContentClient(conn)) + cs, err := resolveContentStore(clicontext) if err != nil { return err diff --git a/images/storage.go b/images/storage.go index 2f4382a0f..050addb48 100644 --- a/images/storage.go +++ b/images/storage.go @@ -103,6 +103,12 @@ func List(tx *bolt.Tx) ([]Image, error) { return images, nil } +func Delete(tx *bolt.Tx, name string) error { + return withImagesBucket(tx, func(bkt *bolt.Bucket) error { + return bkt.DeleteBucket([]byte(name)) + }) +} + func readImage(image *Image, bkt *bolt.Bucket) error { return bkt.ForEach(func(k, v []byte) error { if v == nil {