Skip to content

Commit

Permalink
Fix cpb traverses unneeded paths
Browse files Browse the repository at this point in the history
cpb, it is run on '/' of several images, outputs many unuseful messages
and spoils log aggregation systems.  So cpb excludes device filesystems
and pseudo filesystems from filesystems looking for metadata.

Signed-off-by: ERAMOTO Masaya <eramoto.masaya@jp.fujitsu.com>
  • Loading branch information
eramoto committed Jul 7, 2021
1 parent 20ded32 commit ec260a5
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion util/cpb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,32 @@ func getMetadata() (m *metadata, err error) {
manifestDir: "/manifests",
}

// Exclude device filesystems and pseudo filesystems from filesystems looking for metadata
excludeDir := []string{
"/dev",
"/proc",
"/sys",
}

// Traverse the filesystem looking for metadata
err = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", path, err)
return nil
}
if info.IsDir() {
fmt.Printf("skipping a dir without errors: %+v \n", info.Name())
absPath, err := filepath.Abs(path)
if err != nil {
fmt.Printf("couldn't get the absolute path %q: %v\n", path, err)
return nil
}
for _, v := range excludeDir {
if v == absPath {
fmt.Printf("skipping all files in the dir: %+v \n", absPath)
return filepath.SkipDir
}
}
fmt.Printf("skipping a dir without errors: %+v \n", absPath)
return nil
}
if info.Name() != bundle.AnnotationsFile {
Expand Down

0 comments on commit ec260a5

Please sign in to comment.