Skip to content

Commit

Permalink
Update copy functionality that works on all the platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
kthatipally committed Oct 30, 2024
1 parent d91946d commit 41f2058
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cmd/analyze-bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
Expand Down Expand Up @@ -559,16 +558,14 @@ func (a *analyzeCommand) buildStaticReportFile(ctx context.Context, staticReport
}

func (a *analyzeCommand) buildStaticReportOutput(ctx context.Context, log *os.File) error {
outputFileDestPath := filepath.Join(a.kantraDir, "static-report")
outputFolderSrcPath := filepath.Join(a.kantraDir, "static-report")
outputFolderDestPath := filepath.Join(a.output, "static-report")

// move build dir to user output dir
cmd := exec.Command("cp", "-r", outputFileDestPath, a.output)
cmd.Stdout = log
err := cmd.Run()
//copy static report files to output folder
err := copyFolderContents(outputFolderSrcPath, outputFolderDestPath)
if err != nil {
return err
}

return nil
}

Expand Down
36 changes: 36 additions & 0 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,42 @@ func (a *analyzeCommand) handleDir(p string, tempDir string, basePath string) er
return err
}

func copyFolderContents(src string, dst string) error {
err := os.MkdirAll(dst, os.ModePerm)
if err != nil {
return err
}
source, err := os.Open(src)
if err != nil {
return err
}
defer source.Close()

contents, err := source.Readdir(-1)
if err != nil {
return err
}

for _, item := range contents {
sourcePath := filepath.Join(src, item.Name())
destinationPath := filepath.Join(dst, item.Name())

if item.IsDir() {
// Recursively copy subdirectories
if err := copyFolderContents(sourcePath, destinationPath); err != nil {
return err
}
} else {
// Copy file
if err := copyFileContents(sourcePath, destinationPath); err != nil {
return err
}
}
}

return nil
}

func copyFileContents(src string, dst string) (err error) {
source, err := os.Open(src)
if err != nil {
Expand Down

0 comments on commit 41f2058

Please sign in to comment.