Skip to content

Commit

Permalink
Eliminate "test file busy" errors
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Aug 26, 2024
1 parent af308b0 commit 4c3867e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/svm-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ semver = { workspace = true, features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
sha2 = "0.10"
tempfile = "3.10"
thiserror = "1.0"
url = "2.5"

Expand Down
2 changes: 2 additions & 0 deletions crates/svm-rs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub enum SvmError {
#[error(transparent)]
IoError(#[from] std::io::Error),
#[error(transparent)]
PersistError(#[from] tempfile::PathPersistError),
#[error(transparent)]
ReqwestError(#[from] reqwest::Error),
#[error(transparent)]
SemverError(#[from] semver::Error),
Expand Down
10 changes: 7 additions & 3 deletions crates/svm-rs/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,21 @@ struct Installer<'a> {
impl Installer<'_> {
/// Installs the solc version at the version specific destination and returns the path to the installed solc file.
fn install(self) -> Result<PathBuf, SvmError> {
let solc_path = version_binary(&self.version.to_string());
let named_temp_file = tempfile::NamedTempFile::new_in(data_dir())?;
let (mut f, temp_path) = named_temp_file.into_parts();

let mut f = fs::File::create(&solc_path)?;
#[cfg(target_family = "unix")]
f.set_permissions(Permissions::from_mode(0o755))?;
f.write_all(self.binbytes)?;

if platform::is_nixos() && *self.version >= NIXOS_MIN_PATCH_VERSION {
patch_for_nixos(&solc_path)?;
patch_for_nixos(&temp_path)?;
}

let solc_path = version_binary(&self.version.to_string());

temp_path.persist(&solc_path)?;

Ok(solc_path)
}

Expand Down

0 comments on commit 4c3867e

Please sign in to comment.