Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tokio = "0.1"
url = "2.1.0"
wabt = "0.9.2"
wasmparser = "0.45.0"
structopt = "0.3.8"

[dev-dependencies]
env_logger = "0.6"
Expand Down
18 changes: 1 addition & 17 deletions src/dfx/src/config/cache.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::config::dfx_version;
use crate::lib::error::DfxError::CacheError;
use crate::lib::error::{CacheErrorKind, DfxError, DfxResult};
use crate::lib::error::{CacheErrorKind, DfxResult};
use crate::util;
use indicatif::{ProgressBar, ProgressDrawTarget};
use semver::Version;
use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;
use std::process::ExitStatus;

// POSIX permissions for files in the cache.
const EXEC_READ_USER_ONLY_PERMISSION: u32 = 0o500;
Expand Down Expand Up @@ -188,18 +187,3 @@ pub fn list_versions() -> DfxResult<Vec<Version>> {

Ok(result)
}

pub fn call_cached_dfx(v: &Version) -> DfxResult<ExitStatus> {
let v = format!("{}", v);
let command_path = get_binary_path_from_version(&v, "dfx")?;
if command_path == std::env::current_exe()? {
return Err(DfxError::Unknown(
format_args!("Invalid cache for version {}.", v).to_string(),
));
}

std::process::Command::new(command_path)
.args(std::env::args().skip(1))
.status()
.map_err(DfxError::from)
}
15 changes: 1 addition & 14 deletions src/dfx/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::commands::CliCommand;
use crate::config::{dfx_version, dfx_version_str};
use crate::config::{dfx_version_str};
use crate::lib::environment::{Environment, EnvironmentImpl};
use crate::lib::error::*;
use clap::{App, AppSettings};
Expand Down Expand Up @@ -49,20 +49,7 @@ fn exec(env: &impl Environment, args: &clap::ArgMatches<'_>, cli: &App<'_, '_>)
fn main() {
let result = match EnvironmentImpl::new() {
Ok(env) => {
// If we're not using the right version, forward the call to the cache dfx.
if dfx_version() != env.get_version() {
match crate::config::cache::call_cached_dfx(env.get_version()) {
Ok(status) => std::process::exit(status.code().unwrap_or(0)),
Err(e) => {
eprintln!("Error when trying to forward to project dfx:\n{:?}", e);
eprintln!("Installed executable: {}", dfx_version());
std::process::exit(1)
}
};
}

let matches = cli(&env).get_matches();

exec(&env, &matches, &(cli(&env)))
}
Err(e) => Err(e),
Expand Down