Improve LookPath

This commit is contained in:
Bjørn Erik Pedersen
2020-12-18 18:20:12 +01:00
parent ae2d1bd52d
commit 10ae7c3210
18 changed files with 129 additions and 42 deletions

View File

@@ -19,13 +19,16 @@ import (
"encoding/hex"
"io"
"io/ioutil"
"os/exec"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"github.com/cli/safeexec"
"github.com/gohugoio/hugo/common/hexec"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/loggers"
@@ -146,10 +149,10 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
binary := csiBinPath
if _, err := exec.LookPath(binary); err != nil {
if _, err := safeexec.LookPath(binary); err != nil {
// Try PATH
binary = binaryName
if _, err := exec.LookPath(binary); err != nil {
if _, err := safeexec.LookPath(binary); err != nil {
// This may be on a CI server etc. Will fall back to pre-built assets.
return herrors.ErrFeatureNotAvailable
}
@@ -186,7 +189,10 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
cmdArgs = append(cmdArgs, optArgs...)
}
cmd := exec.Command(binary, cmdArgs...)
cmd, err := hexec.SafeCommand(binary, cmdArgs...)
if err != nil {
return err
}
var errBuf bytes.Buffer
infoW := loggers.LoggerToWriterWithPrefix(logger.Info(), "postcss")