1
0

feat: explicit list of source files

This commit is contained in:
dump_stack() 2024-04-22 15:58:35 +00:00
parent 331876127a
commit a79ea1905a
Signed by: dump_stack
GPG Key ID: C9905BA72B5E02BB
2 changed files with 44 additions and 6 deletions

View File

@ -134,8 +134,12 @@ type Patch struct {
type Artifact struct {
Name string
Type ArtifactType
TestFiles []FileTransfer
SourcePath string
SourceFiles []string
TestFiles []FileTransfer
Targets []Target
Script string

View File

@ -9,6 +9,7 @@ import (
"math/rand"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
@ -112,7 +113,11 @@ func Build(flog zerolog.Logger, tmp string, ka Artifact,
outdir = tmp + "/source"
if len(ka.SourceFiles) == 0 {
err = copy.Copy(ka.SourcePath, outdir)
} else {
err = CopyFiles(ka.SourcePath, ka.SourceFiles, outdir)
}
if err != nil {
return
}
@ -226,6 +231,35 @@ type Result struct {
InternalErrorString string
}
func CopyFiles(path string, files []string, dest string) (err error) {
err = os.MkdirAll(dest, os.ModePerm)
if err != nil {
return
}
for _, sf := range files {
if sf[0] == '/' {
err = CopyFile(sf, filepath.Join(dest, filepath.Base(sf)))
if err != nil {
return
}
continue
}
err = os.MkdirAll(filepath.Join(dest, filepath.Dir(sf)), os.ModePerm)
if err != nil {
return
}
err = CopyFile(filepath.Join(path, sf), filepath.Join(dest, sf))
if err != nil {
return
}
}
return
}
func CopyFile(sourcePath, destinationPath string) (err error) {
sourceFile, err := os.Open(sourcePath)
if err != nil {