diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2017-11-13 15:11:15 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2017-11-13 15:11:15 +0300 |
commit | 246430ba347a892b827437024160279c1e1730b4 (patch) | |
tree | 942e49e83372a8c4e5345218babc935c800d893f | |
parent | c757efaaa0267ec823ddc0858cf6ec930e93a074 (diff) |
Use a symlink to pass the linguist path
-rw-r--r-- | internal/linguist/linguist.go | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/internal/linguist/linguist.go b/internal/linguist/linguist.go index 42f8f0e4f..f2158a566 100644 --- a/internal/linguist/linguist.go +++ b/internal/linguist/linguist.go @@ -53,21 +53,30 @@ func Color(language string) string { // LoadColors loads the name->color map from the Linguist gem. func LoadColors() error { - // We can't use 'bundle show' because that sometimes prints garbage on - // its stdout. - rubyScript := `print Bundler.rubygems.find_name('github-linguist').first.full_gem_path` - cmd := exec.Command("bundle", "exec", "ruby", "-e", rubyScript) + linguistPathSymlink, err := ioutil.TempFile("", "gitaly-linguist-path") + if err != nil { + return err + } + defer os.Remove(linguistPathSymlink.Name()) + + if err := linguistPathSymlink.Close(); err != nil { + return err + } + + // We use a symlink because we cannot trust Bundler to not print garbage + // on its stdout. + rubyScript := `FileUtils.ln_sf(Bundler.rubygems.find_name('github-linguist').first.full_gem_path, ARGV.first)` + cmd := exec.Command("bundle", "exec", "ruby", "-rfileutils", "-e", rubyScript, linguistPathSymlink.Name()) cmd.Dir = config.Config.Ruby.Dir - linguistPath, err := cmd.Output() - if err != nil { + if err := cmd.Run(); err != nil { if exitError, ok := err.(*exec.ExitError); ok { err = fmt.Errorf("%v; stderr: %q", exitError, exitError.Stderr) } return err } - languageJSON, err := ioutil.ReadFile(path.Join(string(linguistPath), "lib/linguist/languages.json")) + languageJSON, err := ioutil.ReadFile(path.Join(linguistPathSymlink.Name(), "lib/linguist/languages.json")) if err != nil { return err } |