Skip to content

Commit e42ab8a

Browse files
authored
fix(avm): Using a temporary installation dir on cargo install calls to prevent cargo erroring out due to existing anchor symlink in .avm/bin (solana-foundation#4343)
1 parent c820041 commit e42ab8a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The minor version will be incremented upon a breaking change and the patch versi
1717
### Fixes
1818

1919
- lang: Fix incorrect deserialization for dynamically sized types when using `lazy-account` ([#4319](https://github.com/solana-foundation/anchor/pull/4319))
20+
- avm: Using a temporary installation dir on cargo install calls to prevent cargo erroring out due to existing `anchor` symlink in `.avm/bin` ([4343](https://github.com/solana-foundation/anchor/pull/4343))
2021

2122
### Breaking
2223

avm/src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ pub fn get_bin_dir_path() -> PathBuf {
5252
AVM_HOME.join("bin")
5353
}
5454

55+
/// Path to the temporary folder for cargo install
56+
pub fn get_tmp_install_dir_path() -> PathBuf {
57+
AVM_HOME.join("tmp")
58+
}
59+
60+
/// Path to the temporary bin folder of cargo install
61+
pub fn get_tmp_bin_dir_path() -> PathBuf {
62+
AVM_HOME.join("tmp").join("bin")
63+
}
64+
5565
/// Path to the binary for the given version
5666
pub fn version_binary_path(version: &Version) -> PathBuf {
5767
get_bin_dir_path().join(format!("anchor-{version}"))
@@ -367,7 +377,11 @@ pub fn install_version(
367377
"anchor-cli".into(),
368378
"--locked".into(),
369379
"--root".into(),
370-
AVM_HOME.to_str().unwrap().into(),
380+
// can't install directly to `.avm/` because additional symlinks were
381+
// added to the .avm/bin folder that can cause cargo to error out during installs
382+
// simply removing the creation of those links would not remove them from user machines
383+
// and we don't want to remove them because they may have been created by the user
384+
get_tmp_install_dir_path().to_str().unwrap().into(),
371385
];
372386
match install_target {
373387
InstallTarget::Version(version) => {
@@ -440,7 +454,7 @@ pub fn install_version(
440454
));
441455
}
442456

443-
let bin_dir = get_bin_dir_path();
457+
let bin_dir = get_tmp_bin_dir_path();
444458
let bin_name = if cfg!(target_os = "windows") {
445459
"anchor.exe"
446460
} else {

0 commit comments

Comments
 (0)