add a wrapper to combine both Python & Rust EdenFS CLI

Reviewed By: xavierd

Differential Revision: D25792324

fbshipit-source-id: 2e54f27caa830076168b7f178b6a95718eeb9f92
This commit is contained in:
Zeyi (Rice) Fan 2021-02-10 16:50:13 -08:00 committed by Facebook GitHub Bot
parent f55a022f89
commit dc22fd8777

View File

@ -19,18 +19,35 @@ use crate::opt::Opt;
fn process_opt(_opt: Opt) -> Result<()> {
Ok(())
}
fn fallback() -> Result<()> {
let binary = std::env::current_exe().context("unable to locate Python binary")?;
let python_binary = binary
.parent()
.ok_or_else(|| anyhow!("unable to locate Python binary"))?
.join("edenfsctl.real");
let mut cmd = Command::new(python_binary);
fn python_fallback() -> Result<Command> {
if let Ok(args) = std::env::var("EDENFSCTL_REAL") {
// We might get a command starting with python.exe here instead of a simple path.
let mut parts = args.split_ascii_whitespace();
let binary = parts
.next()
.ok_or_else(|| anyhow!("invalid fallback environment variable: {:?}", args))?;
let mut cmd = Command::new(binary);
cmd.args(parts);
Ok(cmd)
} else {
let binary = std::env::current_exe().context("unable to locate Python binary")?;
let python_binary = binary
.parent()
.ok_or_else(|| anyhow!("unable to locate Python binary"))?
.join("edenfsctl.real");
Ok(Command::new(python_binary))
}
}
fn fallback() -> Result<()> {
let mut cmd = python_fallback()?;
// skip arg0
cmd.args(std::env::args().skip(1));
#[cfg(windows)]
{
// Windows doesn't have exec, so we have to open a subprocess
cmd.status()
.with_context(|| format!("failed to execute: {:?}", cmd))?;
Ok(())
@ -38,6 +55,8 @@ fn fallback() -> Result<()> {
#[cfg(unix)]
{
// `.exec()` should take over the process, if we ever get to return this Err, then it means
// exec has failed, hence an error.
Err(cmd.exec()).with_context(|| format!("failed to execute {:?}", cmd))
}
}