Skip to content

Commit

Permalink
fix: dfx extension install will no longer create a corrupt cache dire…
Browse files Browse the repository at this point in the history
  • Loading branch information
ericswanson-dfinity committed Nov 7, 2023
1 parent 12a8ea1 commit 565e959
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

# UNRELEASED

=== fix: dfx extension install can no longer create a corrupt cache directory

Running `dfx cache delete && dfx extension install nns` would previously
create a cache directory containing only an `extensions` subdirectory.
dfx only looks for the existence of a cache version subdirectory to
determine whether it has been installed. The end result was that later
commands would fail when the cache did not contain expected files.

=== feat: Read dfx canister install argument from a file

Enables passing large arguments that cannot be passed directly in the command line using the `--argument-file` flag. For example `dfx canister install --argument-file ./my/argument/file.txt my_canister_name`.
Expand Down
6 changes: 6 additions & 0 deletions e2e/tests-dfx/extension.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ teardown() {
standard_teardown
}

@test "extension install with an empty cache does not create a corrupt cache" {
dfx cache delete
dfx extension install nns --version 0.2.1
dfx_start
}

@test "install extension from official registry" {
assert_command_fail dfx snsx

Expand Down
4 changes: 4 additions & 0 deletions src/dfx/src/commands/extension/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use clap::Parser;
use clap::Subcommand;
use dfx_core::error::extension::ExtensionError;
use semver::Version;
use crate::config::cache::DiskBasedCache;

#[derive(Parser)]
pub struct InstallOpts {
Expand All @@ -19,6 +20,9 @@ pub struct InstallOpts {
}

pub fn exec(env: &dyn Environment, opts: InstallOpts) -> DfxResult<()> {
// creating an `extensions` directory in an otherwise empty cache directory would
// cause the cache to be considered "installed" and later commands would fail
DiskBasedCache::install(&env.get_cache().version_str())?;
let spinner = env.new_spinner(format!("Installing extension: {}", opts.name).into());
let mgr = env.new_extension_manager()?;
let effective_extension_name = opts.install_as.clone().unwrap_or_else(|| opts.name.clone());
Expand Down

0 comments on commit 565e959

Please sign in to comment.