Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Commit

Permalink
stage0/image_verify: don't always render images
Browse files Browse the repository at this point in the history
This avoids rendering an image that has not yet been rendered, and
skips doing the verification for it since it's a nonsensical operation.
  • Loading branch information
euank committed Apr 9, 2017
1 parent 0cbd2a6 commit 745affc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 24 additions & 3 deletions rkt/image_verify.go
Expand Up @@ -15,15 +15,18 @@
package main

import (
"github.com/coreos/rkt/store/imagestore"
"github.com/coreos/rkt/store/treestore"
"os"

"github.com/hashicorp/errwrap"
"github.com/rkt/rkt/store/imagestore"
"github.com/rkt/rkt/store/treestore"
"github.com/spf13/cobra"
)

var (
cmdImageVerify = &cobra.Command{
Use: "verify IMAGE...",
Short: "Verify one or more images in the local store",
Short: "Verify one or more rendered images in the local store",
Long: `Verify is able to check that, based on the stored hash value, a rendered image on disk has not changed.
This command may be used if the user suspects disk corruption might have damaged the rkt store.`,
Expand Down Expand Up @@ -65,6 +68,10 @@ func runVerifyImage(cmd *cobra.Command, args []string) int {
return 254
}
_, err = ts.Check(id)
if isNotRenderedErr(err) {
stdout.Printf("image %q not rendered; no verification needed", img)
continue
}
if err != nil {
stdout.Printf("tree cache verification failed for image %s: %v; rebuilding...", img, err)
_, _, err = ts.Render(key, true)
Expand All @@ -78,3 +85,17 @@ func runVerifyImage(cmd *cobra.Command, args []string) int {
}
return 0
}

func isNotRenderedErr(err error) bool {
containsIsNotExist := false
containsReadHashErr := false
errwrap.Walk(err, func(e error) {
if os.IsNotExist(e) {
containsIsNotExist = true
}
if e == treestore.ErrReadHashfile {
containsReadHashErr = true
}
})
return containsIsNotExist && containsReadHashErr
}
6 changes: 5 additions & 1 deletion store/treestore/tree.go
Expand Up @@ -56,6 +56,10 @@ const (
minlenKey = len(hashPrefix) + 2 // at least sha512-aa
)

var (
ErrReadHashfile = errors.New("cannot read hash file")
)

// Store represents a store of rendered ACIs
type Store struct {
dir string
Expand Down Expand Up @@ -362,7 +366,7 @@ func (ts *Store) check(id string) (string, error) {
treepath := ts.GetPath(id)
hash, err := ioutil.ReadFile(filepath.Join(treepath, hashfilename))
if err != nil {
return "", errwrap.Wrap(errors.New("cannot read hash file"), err)
return "", errwrap.Wrap(ErrReadHashfile, err)
}
curhash, err := ts.Hash(id)
if err != nil {
Expand Down

0 comments on commit 745affc

Please sign in to comment.