github.com/quay/claircore@v1.5.28/java/common.go (about) 1 package java 2 3 import ( 4 "context" 5 "io/fs" 6 "strings" 7 8 "github.com/quay/claircore/java/jar" 9 ) 10 11 // Archives returns a slice of names that are probably archives, based on name 12 // and size. Callers should still check that the named file is valid. 13 func archives(_ context.Context, sys fs.FS) (out []string, err error) { 14 return out, fs.WalkDir(sys, ".", func(p string, d fs.DirEntry, err error) error { 15 // Incoming checks: 16 switch { 17 case err != nil: 18 return err 19 case d.IsDir(): 20 return nil 21 } 22 fi, err := d.Info() 23 if err != nil { 24 return err 25 } 26 27 // Prefix check: 28 if strings.HasPrefix(fi.Name(), ".wh.") { 29 return nil 30 } 31 32 // Extension check: 33 if !jar.ValidExt(fi.Name()) { 34 return nil 35 } 36 37 // Size check: 38 if fi.Size() < jar.MinSize { 39 return nil 40 } 41 42 // Probably an archive. 43 out = append(out, p) 44 return nil 45 }) 46 }