Skip to content

Commit 208c286

Browse files
committed
fix:修复路径检测
1 parent 477c500 commit 208c286

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

cpu/cputest.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,24 @@ func formatScoreOutput(language string, threads int, score string) string {
202202
}
203203
}
204204

205+
// lookGeekbench searches PATH for common geekbench binary names used both by
206+
// dgb.sh (geekbench) and manually extracted official tarballs (geekbench6,
207+
// geekbench5, geekbench4). Returns the full path or "".
208+
func lookGeekbench() string {
209+
for _, name := range []string{"geekbench", "geekbench6", "geekbench5", "geekbench4"} {
210+
if path, err := exec.LookPath(name); err == nil {
211+
return path
212+
}
213+
}
214+
return ""
215+
}
216+
205217
// resolveGeekbenchBinary returns the path to the geekbench binary and, when the
206218
// embedded binary is used, the temp directory that the caller must remove.
207-
// It checks the system PATH first, then falls back to the embedded binary.
219+
// It checks the system PATH first (including dgb.sh-installed binaries), then
220+
// falls back to the embedded binary.
208221
func resolveGeekbenchBinary() (binPath, tmpDir string, err error) {
209-
if path, lookErr := exec.LookPath("geekbench"); lookErr == nil {
222+
if path := lookGeekbench(); path != "" {
210223
return path, "", nil
211224
}
212225
return extractEmbeddedGeekbench()
@@ -299,17 +312,26 @@ func GeekBenchTest(language, testThread string) string {
299312
if versionErr != nil {
300313
logError("geekbench version check warning", versionErr)
301314
if version == "" {
302-
// Binary produced no output – try downloading the latest binary.
315+
// Binary produced no output – first try any dgb/system-installed
316+
// geekbench that may have appeared in PATH (geekbench6, geekbench5…),
317+
// then fall back to downloading the latest from CDN.
303318
if cleanDir != "" {
304319
os.RemoveAll(cleanDir)
305320
cleanDir = ""
306321
}
307-
freshBin, freshDir, dlErr := downloadAndExtractGeekbench()
308-
if dlErr != nil {
309-
logError("geekbench download fallback failed", dlErr)
310-
return ""
322+
var freshBin, freshDir string
323+
var dlErr error
324+
if sysBin := lookGeekbench(); sysBin != "" && sysBin != geekbenchBin {
325+
// A different system binary exists; try it.
326+
freshBin = sysBin
327+
} else {
328+
freshBin, freshDir, dlErr = downloadAndExtractGeekbench()
329+
if dlErr != nil {
330+
logError("geekbench download fallback failed", dlErr)
331+
return ""
332+
}
333+
cleanDir = freshDir
311334
}
312-
cleanDir = freshDir
313335
geekbenchBin = freshBin
314336
// Re-run version check with the freshly downloaded binary.
315337
versionOut2, versionErr2 := exec.Command(geekbenchBin, "--version").CombinedOutput()

0 commit comments

Comments
 (0)