mirror of
https://github.com/securego/gosec.git
synced 2024-11-06 03:55:50 +00:00
59fbf7446d
Effectively using filepath.Glob to build a set of files and directories to exclude from the scan. (ref: https://golang.org/pkg/path/filepath/#Glob)
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
// (c) Copyright 2016 Hewlett Packard Enterprise Development LP
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
type filelist struct {
|
|
paths map[string]bool
|
|
globs []string
|
|
}
|
|
|
|
func newFileList(paths ...string) *filelist {
|
|
|
|
f := &filelist{
|
|
make(map[string]bool),
|
|
make([]string, 0),
|
|
}
|
|
|
|
for _, path := range paths {
|
|
f.Set(path)
|
|
}
|
|
return f
|
|
}
|
|
|
|
func (f *filelist) String() string {
|
|
return strings.Join(f.globs, ", ")
|
|
}
|
|
|
|
func (f *filelist) Set(path string) error {
|
|
f.globs = append(f.globs, path)
|
|
matches, e := filepath.Glob(path)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
for _, each := range matches {
|
|
abs, e := filepath.Abs(each)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
f.paths[abs] = true
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (f filelist) Contains(path string) bool {
|
|
_, present := f.paths[path]
|
|
return present
|
|
}
|
|
|
|
/*
|
|
func (f filelist) Dump() {
|
|
for k, _ := range f.paths {
|
|
println(k)
|
|
}
|
|
}
|
|
*/
|