Merge pull request #222 from AkihiroSuda/fix-debug-meta

buildctl: fix dump-metadata
docker-18.09
Tõnis Tiigi 2017-12-15 11:05:06 -08:00 committed by GitHub
commit 51fc6661bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 5 deletions

View File

@ -3,6 +3,8 @@ package debug
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
@ -22,13 +24,43 @@ var DumpMetadataCommand = cli.Command{
},
},
Action: func(clicontext *cli.Context) error {
dbFile := filepath.Join(clicontext.String("root"), "metadata.db")
return dumpBolt(dbFile, func(k, v []byte) string {
return fmt.Sprintf("%q: %s", string(k), string(v))
})
dbFiles, err := findMetadataDBFiles(clicontext.String("root"))
if err != nil {
return err
}
for _, dbFile := range dbFiles {
fmt.Printf("===== %s =====\n", dbFile)
if err := dumpBolt(dbFile, func(k, v []byte) string {
return fmt.Sprintf("%q: %s", string(k), string(v))
}); err != nil {
return err
}
}
return nil
},
}
func findMetadataDBFiles(root string) ([]string, error) {
dirs, err := ioutil.ReadDir(root)
if err != nil {
return nil, err
}
var files []string
for _, dir := range dirs {
if !dir.IsDir() {
continue
}
p := filepath.Join(root, dir.Name(), "metadata.db")
_, err := os.Stat(p)
if err == nil {
files = append(files, p)
} else if !os.IsNotExist(err) {
return nil, err
}
}
return files, nil
}
func dumpBolt(dbFile string, stringifier func(k, v []byte) string) error {
if dbFile == "" {
return errors.New("dbfile not specified")

View File

@ -30,7 +30,7 @@ func NewWorkerOpt(root string) (worker.WorkerOpt, error) {
if err := os.MkdirAll(root, 0700); err != nil {
return opt, err
}
md, err := metadata.NewStore(filepath.Join(root, name+"-metadata.db"))
md, err := metadata.NewStore(filepath.Join(root, "metadata.db"))
if err != nil {
return opt, err
}