func (g *copy) Run() error {
	var destPath, srcPath string
	var files []string
	srcPath = g.defFile.Source
	destPath = filepath.Join(g.sourceDir, g.defFile.Source)
	if g.defFile.Path != "" {
		destPath = filepath.Join(g.sourceDir, g.defFile.Path)
	}
	dirFiles, err := ioutil.ReadDir(filepath.Dir(srcPath))
	if err != nil {
		return fmt.Errorf("Failed to read directory %q: %w", filepath.Dir(srcPath), err)
	}
	for _, f := range dirFiles {
		match, err := filepath.Match(srcPath, filepath.Join(filepath.Dir(srcPath), f.Name()))
		if err != nil {
			return fmt.Errorf("Failed to match pattern: %w", err)
		}
		if match {
			files = append(files, filepath.Join(filepath.Dir(srcPath), f.Name()))
		}
	}
	switch len(files) {
	case 0:
		_, err = os.Stat(srcPath)
		if err != nil {
			return fmt.Errorf("Failed to stat file %q: %w", srcPath, err)
		}
		err = g.doCopy(srcPath, destPath, g.defFile)
	case 1:
		err = g.doCopy(srcPath, destPath, g.defFile)
	default:
		g.defFile.Path = g.defFile.Path + "/"
		for _, f := range files {
			err = g.doCopy(f, destPath, g.defFile)
			if err != nil {
				break
			}
		}
	}
	if err != nil {
		return fmt.Errorf("Failed to copy file(s): %w", err)
	}
	return nil
}
Run copies a file to the container.
package generators
import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"github.com/lxc/distrobuilder/image"
	"github.com/lxc/distrobuilder/shared"
	lxd "github.com/lxc/lxd/shared"
)
type copy struct {
	common
}
func (g *copy) RunLXC(img *image.LXCImage, target shared.DefinitionTargetLXC) error {
	return g.Run()
}
func (g *copy) RunLXD(img *image.LXDImage, target shared.DefinitionTargetLXD) error {
	return g.Run()
}