Skip to content

Commit 6f59a3b

Browse files
authored
Fix cpb traverses unneeded paths (#2239)
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 <[email protected]>
1 parent dbf0c02 commit 6f59a3b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

util/cpb/main.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,32 @@ func getMetadata() (m *metadata, err error) {
8484
manifestDir: "/manifests",
8585
}
8686

87+
// Exclude device filesystems and pseudo filesystems from filesystems looking for metadata
88+
excludeDir := []string{
89+
"/dev",
90+
"/proc",
91+
"/sys",
92+
}
93+
8794
// Traverse the filesystem looking for metadata
8895
err = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
8996
if err != nil {
9097
fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", path, err)
9198
return nil
9299
}
93100
if info.IsDir() {
94-
fmt.Printf("skipping a dir without errors: %+v \n", info.Name())
101+
absPath, err := filepath.Abs(path)
102+
if err != nil {
103+
fmt.Printf("couldn't get the absolute path %q: %v\n", path, err)
104+
return nil
105+
}
106+
for _, v := range excludeDir {
107+
if v == absPath {
108+
fmt.Printf("skipping all files in the dir: %+v \n", absPath)
109+
return filepath.SkipDir
110+
}
111+
}
112+
fmt.Printf("skipping a dir without errors: %+v \n", absPath)
95113
return nil
96114
}
97115
if info.Name() != bundle.AnnotationsFile {

0 commit comments

Comments
 (0)