Skip to content

Commit

Permalink
avm: Handle empty .version file (#1407)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlinton committed Feb 8, 2022
1 parent a14a829 commit afef73b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion avm/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "avm"
version = "0.1.0"
version = "0.20.1"
edition = "2018"

[[bin]]
Expand Down
7 changes: 6 additions & 1 deletion avm/src/lib.rs
Expand Up @@ -98,6 +98,11 @@ pub fn install_version(version: &Version) -> Result<()> {
&AVM_HOME.join("bin").join("anchor"),
&AVM_HOME.join("bin").join(format!("anchor-{}", version)),
)?;
// If .version file is empty or not parseable, write the newly installed version to it
if current_version().is_err() {
let mut current_version_file = fs::File::create(current_version_file_path().as_path())?;
current_version_file.write_all(version.to_string().as_bytes())?;
}
Ok(())
}

Expand Down Expand Up @@ -174,7 +179,7 @@ pub fn list_versions() -> Result<()> {
if installed_versions.contains(v) {
flags.push("installed");
}
if current_version().unwrap() == v.clone() {
if current_version().is_ok() && current_version().unwrap() == v.clone() {
flags.push("current");
}
if flags.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion avm/src/main.rs
Expand Up @@ -5,7 +5,7 @@ use semver::Version;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

#[derive(Parser)]
#[clap(name = "avm", about = "Anchor version manager")]
#[clap(name = "avm", about = "Anchor version manager", version)]
pub struct Cli {
#[clap(subcommand)]
command: Commands,
Expand Down

0 comments on commit afef73b

Please sign in to comment.