2016-07-20 11:02:01 +01:00
|
|
|
// (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"
|
|
|
|
)
|
|
|
|
|
2016-09-10 22:55:12 +01:00
|
|
|
type filelist struct {
|
|
|
|
paths map[string]bool
|
|
|
|
globs []string
|
2016-07-20 11:02:01 +01:00
|
|
|
}
|
|
|
|
|
2016-09-10 22:55:12 +01:00
|
|
|
func newFileList(paths ...string) *filelist {
|
2016-07-27 05:47:09 +01:00
|
|
|
|
2016-09-10 22:55:12 +01:00
|
|
|
f := &filelist{
|
|
|
|
make(map[string]bool),
|
|
|
|
make([]string, 0),
|
2016-07-20 11:02:01 +01:00
|
|
|
}
|
2016-07-27 05:47:09 +01:00
|
|
|
|
2016-09-10 22:55:12 +01:00
|
|
|
for _, path := range paths {
|
|
|
|
f.Set(path)
|
|
|
|
}
|
|
|
|
return f
|
|
|
|
}
|
2016-07-27 05:47:09 +01:00
|
|
|
|
2016-09-10 22:55:12 +01:00
|
|
|
func (f *filelist) String() string {
|
|
|
|
return strings.Join(f.globs, ", ")
|
|
|
|
}
|
2016-07-27 05:47:09 +01:00
|
|
|
|
2016-09-10 22:55:12 +01:00
|
|
|
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
|
2016-08-24 18:26:18 +01:00
|
|
|
}
|
2016-09-10 22:55:12 +01:00
|
|
|
f.paths[abs] = true
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2016-08-24 18:26:18 +01:00
|
|
|
|
2016-09-10 22:55:12 +01:00
|
|
|
func (f filelist) Contains(path string) bool {
|
|
|
|
_, present := f.paths[path]
|
|
|
|
return present
|
|
|
|
}
|
2016-07-27 05:47:09 +01:00
|
|
|
|
2016-09-10 22:55:12 +01:00
|
|
|
/*
|
|
|
|
func (f filelist) Dump() {
|
|
|
|
for k, _ := range f.paths {
|
|
|
|
println(k)
|
2016-07-20 11:02:01 +01:00
|
|
|
}
|
|
|
|
}
|
2016-09-10 22:55:12 +01:00
|
|
|
*/
|