Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG-FIX]: Fix issue with 'cp' command not compatible on Windows for containerless analyze #366

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading