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

Fix path issue #37

Merged
merged 1 commit into from
Nov 13, 2023
Merged
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
14 changes: 7 additions & 7 deletions internal/scan/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GetRubyDeps(path string) (map[string]string, error) {

if gemspec != "" {
log.Debugf("Found %s, parsing", gemspec)
return runRubyParser(gemSpecParser, gemspec)
return runRubyParser(gemSpecParser, gemspec, baseDir)
}

lockPath := filepath.Join(baseDir, "Gemfile.lock")
Expand All @@ -66,18 +66,19 @@ func GetRubyDeps(path string) (map[string]string, error) {
cmd := exec.CommandContext(ctx, "env", fmt.Sprintf("--chdir=%s", baseDir), "bundle", "lock")
data, err := cmd.CombinedOutput()
if err != nil {
log.Errorf("couldn't create %s: %v", lockPath, err)
log.Debugf("couldn't create %s: %v", lockPath, err)
log.Debugf("bundle lock output: %v", string(data))
}
log.Debugf("Created %s", lockPath)
} else {
log.Errorf("Unexpected error: %v", err)
return nil, err
}
}
return runRubyParser(gemFileParser, baseDir)
return runRubyParser(gemFileParser, ".", baseDir)
}

func runRubyParser(script Script, target string) (map[string]string, error) {
func runRubyParser(script Script, arg string, dir string) (map[string]string, error) {
gathered := make(map[string]string)

g, err := os.CreateTemp("", script.Name)
Expand All @@ -91,9 +92,8 @@ func runRubyParser(script Script, target string) (map[string]string, error) {
log.Errorf("Could not write ruby script to %s: %s", g.Name(), err)
return gathered, err
}
dir := filepath.Dir(target)
name := filepath.Base(target)
args := []string{fmt.Sprintf("--chdir=%s", dir), "ruby", g.Name(), name}

args := []string{fmt.Sprintf("--chdir=%s", dir), "ruby", g.Name(), arg}
log.Debugf("Running env %v", args)
cmd := exec.Command("env", args...)
data, err := cmd.Output()
Expand Down