Skip to content

Commit 04ba059

Browse files
committed
Also search next to findns executable when looking for binaries
Users expect placing dnstt-client/slipstream-client next to findns.exe to work, even when running from a different directory.
1 parent 5b32569 commit 04ba059

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

cmd/root.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ func writeReport(mode string, results []scanner.Result, elapsed time.Duration, s
8787
return nil
8888
}
8989

90-
// findBinary looks for a binary in PATH first, then in the current directory.
90+
// findBinary looks for a binary in PATH, then in the current directory,
91+
// then next to the findns executable itself.
9192
// On Linux, exec.LookPath does NOT check the current directory, so users placing
9293
// dnstt-client next to the scanner get "not found". This fixes that.
9394
func findBinary(name string) (string, error) {
@@ -96,17 +97,26 @@ func findBinary(name string) (string, error) {
9697
return p, nil
9798
}
9899

99-
// Check current directory
100100
local := name
101101
if runtime.GOOS == "windows" && filepath.Ext(name) == "" {
102102
local = name + ".exe"
103103
}
104+
105+
// Check current directory
104106
if abs, err := filepath.Abs(local); err == nil {
105107
if _, err := os.Stat(abs); err == nil {
106108
return abs, nil
107109
}
108110
}
109111

112+
// Check directory where findns executable is located
113+
if exe, err := os.Executable(); err == nil {
114+
candidate := filepath.Join(filepath.Dir(exe), local)
115+
if _, err := os.Stat(candidate); err == nil {
116+
return candidate, nil
117+
}
118+
}
119+
110120
hint := ""
111121
switch name {
112122
case "dnstt-client":
@@ -115,7 +125,7 @@ func findBinary(name string) (string, error) {
115125
hint = "\n\nDownload from: https://github.com/Mygod/slipstream-rust/releases"
116126
}
117127

118-
return "", fmt.Errorf("%s not found in PATH or current directory.%s\n\nIf already downloaded, either:\n 1. Move it to a folder in PATH: sudo mv %s /usr/local/bin/\n 2. Or add current directory to PATH: export PATH=$PATH:$(pwd)", name, hint, name)
128+
return "", fmt.Errorf("%s not found in PATH, current directory, or next to findns.%s\n\nIf already downloaded, either:\n 1. Place it next to the findns executable\n 2. Move it to a folder in PATH: sudo mv %s /usr/local/bin/\n 3. Or add current directory to PATH: export PATH=$PATH:$(pwd)", name, hint, name)
119129
}
120130

121131
func isTTY() bool {

0 commit comments

Comments
 (0)