Skip to content

Commit 72dcb66

Browse files
committed
fix: qchat path for deb installations
1 parent 3fa6c7e commit 72dcb66

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

crates/q_cli/src/cli/mod.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::io::{
2525
Write as _,
2626
stdout,
2727
};
28+
use std::path::PathBuf;
2829
use std::process::ExitCode;
2930

3031
use anstream::{
@@ -57,15 +58,13 @@ use fig_proto::local::UiElement;
5758
use fig_settings::sqlite::database;
5859
use fig_util::directories::home_local_bin;
5960
use fig_util::{
60-
CHAT_BINARY_NAME,
6161
CLI_BINARY_NAME,
6262
PRODUCT_NAME,
6363
directories,
6464
manifest,
6565
system_info,
6666
};
6767
use internal::InternalSubcommand;
68-
use macos_utils::bundle::get_bundle_path_for_executable;
6968
use serde::Serialize;
7069
use tokio::signal::ctrl_c;
7170
use tracing::{
@@ -376,14 +375,6 @@ impl Cli {
376375
}
377376

378377
pub async fn execute_chat(subcmd: &str, args: Option<Vec<String>>, enforce_login: bool) -> Result<ExitCode> {
379-
cfg_if::cfg_if! {
380-
if #[cfg(target_os = "macos")] {
381-
let path = get_bundle_path_for_executable(CHAT_BINARY_NAME).unwrap_or(home_local_bin()?.join(CHAT_BINARY_NAME));
382-
} else {
383-
let path = home_local_bin()?.join(CHAT_BINARY_NAME);
384-
}
385-
}
386-
387378
if enforce_login {
388379
assert_logged_in().await?;
389380
}
@@ -399,7 +390,7 @@ impl Cli {
399390
}
400391
}
401392

402-
let mut cmd = tokio::process::Command::new(&path);
393+
let mut cmd = tokio::process::Command::new(qchat_path()?);
403394
cmd.arg(subcmd);
404395
if let Some(args) = args {
405396
cmd.args(args);
@@ -557,6 +548,28 @@ async fn launch_dashboard(help_fallback: bool) -> Result<ExitCode> {
557548
Ok(ExitCode::SUCCESS)
558549
}
559550

551+
#[cfg(target_os = "linux")]
552+
fn qchat_path() -> Result<PathBuf> {
553+
use fig_os_shim::Context;
554+
use fig_util::consts::CHAT_BINARY_NAME;
555+
556+
let ctx = Context::new();
557+
if let Some(path) = ctx.process_info().current_pid().exe() {
558+
// This is required for deb installations.
559+
if path.starts_with("/usr/bin") {
560+
return Ok(PathBuf::from("/usr/bin").join(CHAT_BINARY_NAME));
561+
}
562+
}
563+
Ok(home_local_bin()?.join(CHAT_BINARY_NAME))
564+
}
565+
566+
#[cfg(target_os = "macos")]
567+
fn qchat_path() -> Result<PathBuf> {
568+
use macos_utils::bundle::get_bundle_path_for_executable;
569+
570+
Ok(get_bundle_path_for_executable(CHAT_BINARY_NAME).unwrap_or(home_local_bin()?.join(CHAT_BINARY_NAME)))
571+
}
572+
560573
#[cfg(test)]
561574
mod test {
562575
use super::*;

0 commit comments

Comments
 (0)