From 4c490fc450f4bb8b7efb39c4b0072506679a1526 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Mon, 22 Apr 2024 15:58:35 +0000 Subject: [PATCH] feat: explicit list of source files --- artifact/artifact.go | 14 +++++++++----- artifact/process.go | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/artifact/artifact.go b/artifact/artifact.go index bc09cf9..dd1510a 100644 --- a/artifact/artifact.go +++ b/artifact/artifact.go @@ -132,11 +132,15 @@ type Patch struct { // Artifact is for .out-of-tree.toml type Artifact struct { - Name string - Type ArtifactType - TestFiles []FileTransfer - SourcePath string - Targets []Target + Name string + Type ArtifactType + + SourcePath string + SourceFiles []string + + TestFiles []FileTransfer + + Targets []Target Script string diff --git a/artifact/process.go b/artifact/process.go index 769d8e7..416b98b 100644 --- a/artifact/process.go +++ b/artifact/process.go @@ -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" - err = copy.Copy(ka.SourcePath, outdir) + 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 {