* Copyright 2016-2017 Gary Kramlich <grim@reaperworld.com> * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. "github.com/aphistic/gomol" "bitbucket.org/rw_grim/convey/environment" "bitbucket.org/rw_grim/convey/state" "bitbucket.org/rw_grim/convey/tasks" "bitbucket.org/rw_grim/convey/yaml" Files yaml.StringOrSlice `yaml:"files"` const exportTemplate = `cp {{.workspace}}:/workspace/{{.source}} {{.destination}}` const zglobTemplate = `run --rm -v {{.workspace}}:/workspace convey/workspace-tools:latest zglob {{.file}}` func checkFilePattern(file string) error { if strings.ContainsRune(file, '*') && strings.ContainsRune(file, ':') { return errWildcardWithDestination func exportFile(name, workSpace, src, dest string, st *state.State) error { params := map[string]interface{}{ dir := filepath.Dir(dest) if err := os.MkdirAll(dir, 0777); err != nil { return Docker(name, exportTemplate, params, st) func exportGlob(name, workSpace, mountPoint, pattern string, st *state.State) error { params := map[string]interface{}{ out, _, err := DockerOutput(fmt.Sprintf("%s-zglob", name), zglobTemplate, params, st) for _, match := range strings.Split(out, "\n") { exportFile(name, workSpace, match, tasks.DestFromSrc(match), st) func (e *Export) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error { fullEnv := environment.Merge(env, st.Environment) files, err := st.MapSlice(e.Files, fullEnv) for _, file := range files { if err := checkFilePattern(file); err != nil { dockerWorkspace := st.Workspace.(*Workspace) if strings.ContainsRune(file, '*') { mountPoint, err := environment.Mapper(dockerWorkspace.mountPoint, fullEnv) if err := exportGlob(name, st.Workspace.Name(), mountPoint, file, st); err != nil { src, dest := tasks.ParseFilePath("", file) if err := exportFile(name, st.Workspace.Name(), src, dest, st); err != nil { func (e *Export) New() tasks.Task { func (e *Export) Valid() error { for _, file := range e.Files { if err := checkFilePattern(file); err != nil {