2020-05-25 15:07:40 -03:00
|
|
|
package extrafiles
|
|
|
|
|
|
|
|
import (
|
2020-09-21 14:47:51 -03:00
|
|
|
"fmt"
|
2020-05-25 15:07:40 -03:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/mattn/go-zglob"
|
|
|
|
)
|
|
|
|
|
2020-05-25 15:18:24 -03:00
|
|
|
// Find resolves extra files globs et al into a map of names/paths or an error.
|
2020-05-25 15:07:40 -03:00
|
|
|
func Find(files []config.ExtraFile) (map[string]string, error) {
|
|
|
|
var result = map[string]string{}
|
|
|
|
for _, extra := range files {
|
|
|
|
if extra.Glob != "" {
|
|
|
|
files, err := zglob.Glob(extra.Glob)
|
|
|
|
if err != nil {
|
2020-09-21 14:47:51 -03:00
|
|
|
return result, fmt.Errorf("globbing failed for pattern %s: %w", extra.Glob, err)
|
2020-05-25 15:07:40 -03:00
|
|
|
}
|
|
|
|
for _, file := range files {
|
|
|
|
info, err := os.Stat(file)
|
|
|
|
if err == nil && info.IsDir() {
|
|
|
|
log.Debugf("ignoring directory %s", file)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var name = filepath.Base(file)
|
|
|
|
if old, ok := result[name]; ok {
|
|
|
|
log.Warnf("overriding %s with %s for name %s", old, file, name)
|
|
|
|
}
|
|
|
|
result[name] = file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|