Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dfx extension install will no longer create a corrupt cache directory #3436

Merged
merged 3 commits into from
Nov 7, 2023
Merged
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
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