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
…ctory (#3436)

Running `dfx extension install <extension>` immediately after installing a new dfx version, or after `dfx cache delete`, would result in a cache directory that contained only an `extensions` subdirectory.

Later, dfx would see that the cache directory exists and therefore not install it.  Then, commands like `dfx start` or `dfx build` would fail due to missing files.

Fixes: https://dfinity.atlassian.net/browse/SDK-1240
  • Loading branch information
ericswanson-dfinity authored Nov 7, 2023
1 parent 79c6786 commit 4854268
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.

=== fix: output_env_file is now considered relative to project root

The .env file location, whether specified as `output_env_file` in dfx.json
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
@@ -1,4 +1,5 @@
use crate::commands::DfxCommand;
use crate::config::cache::DiskBasedCache;
use crate::lib::environment::Environment;
use crate::lib::error::DfxResult;
use clap::Parser;
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 4854268

Please sign in to comment.