Skip to content

Commit 8faed09

Browse files
authored
Merge pull request #437 from rtk-ai/fix/telemetry-windows-paths
fix: detect install method on Windows paths
2 parents 7f7d713 + 81c3e76 commit 8faed09

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/telemetry.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,22 @@ fn detect_install_method() -> &'static str {
137137
Err(_) => return "unknown",
138138
};
139139

140-
// Resolve symlinks to find the real binary location
141140
let real_path = std::fs::canonicalize(&exe)
142141
.unwrap_or(exe)
143142
.to_string_lossy()
144143
.to_string();
145144

146-
if real_path.contains("/Cellar/rtk/") || real_path.contains("/homebrew/") {
145+
install_method_from_path(&real_path)
146+
}
147+
148+
fn install_method_from_path(path: &str) -> &'static str {
149+
if path.contains("/Cellar/rtk/") || path.contains("/homebrew/") {
147150
"homebrew"
148-
} else if real_path.contains("/.cargo/bin/") {
151+
} else if path.contains("/.cargo/bin/") || path.contains("\\.cargo\\bin\\") {
149152
"cargo"
150-
} else if real_path.contains("/.local/bin/") {
153+
} else if path.contains("/.local/bin/") || path.contains("\\.local\\bin\\") {
151154
"script"
152-
} else if real_path.contains("/nix/store/") {
155+
} else if path.contains("/nix/store/") {
153156
"nix"
154157
} else {
155158
"other"
@@ -196,6 +199,22 @@ mod tests {
196199
);
197200
}
198201

202+
#[test]
203+
fn test_install_method_unix_paths() {
204+
assert_eq!(install_method_from_path("/opt/homebrew/Cellar/rtk/0.27.2/bin/rtk"), "homebrew");
205+
assert_eq!(install_method_from_path("/home/user/.cargo/bin/rtk"), "cargo");
206+
assert_eq!(install_method_from_path("/home/user/.local/bin/rtk"), "script");
207+
assert_eq!(install_method_from_path("/nix/store/abc123-rtk/bin/rtk"), "nix");
208+
assert_eq!(install_method_from_path("/usr/local/bin/rtk"), "other");
209+
}
210+
211+
#[test]
212+
fn test_install_method_windows_paths() {
213+
assert_eq!(install_method_from_path(r"C:\Users\dev\.cargo\bin\rtk.exe"), "cargo");
214+
assert_eq!(install_method_from_path(r"C:\Users\dev\.local\bin\rtk.exe"), "script");
215+
assert_eq!(install_method_from_path(r"C:\Program Files\rtk\rtk.exe"), "other");
216+
}
217+
199218
#[test]
200219
fn test_get_stats_returns_tuple() {
201220
let (cmds, top, pct, saved_24h, saved_total) = get_stats();

0 commit comments

Comments
 (0)