set file permissions for downloaded solc

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
Cyrill Leutwiler
2025-03-25 07:33:24 +01:00
parent c69a87238d
commit 382b944bd1
3 changed files with 30 additions and 9 deletions
Generated
+3
View File
@@ -2867,6 +2867,8 @@ name = "revive-dt-config"
version = "0.1.0"
dependencies = [
"clap",
"semver 1.0.26",
"temp-dir",
]
[[package]]
@@ -2884,6 +2886,7 @@ dependencies = [
"revive-dt-format",
"revive-dt-node",
"revive-dt-node-interaction",
"revive-dt-solc-binaries",
"revive-solc-json-interface",
"semver 1.0.26",
"serde",
+1
View File
@@ -20,6 +20,7 @@ revive-dt-format = { version = "0.1.0", path = "crates/format" }
revive-dt-node = { version = "0.1.0", path = "crates/node" }
revive-dt-node-interaction = { version = "0.1.0", path = "crates/node-interaction" }
revive-dt-node-pool = { version = "0.1.0", path = "crates/node-pool" }
revive-dt-solc-binaries = { version = "0.1.0", path = "crates/solc-binaries" }
anyhow = "1.0"
clap = { version = "4", features = ["derive"] }
+26 -9
View File
@@ -5,6 +5,7 @@ use std::{
collections::HashSet,
fs::{File, create_dir_all},
io::Write,
os::unix::fs::PermissionsExt,
path::{Path, PathBuf},
sync::Mutex,
};
@@ -50,17 +51,33 @@ impl SolcCacher {
return Ok(file_path);
}
if file_path.exists() {
self.cached_binaries.insert(file_path.clone());
return Ok(file_path);
}
create_dir_all(directory)?;
let buf = downloader.download()?;
File::create_new(&file_path)
.expect("should not exist because of above early return")
.write_all(&buf)?;
let Ok(mut file) = File::create_new(&file_path) else {
self.cached_binaries.insert(file_path.clone());
return Ok(file_path);
};
file.write_all(&downloader.download()?)?;
#[cfg(unix)]
{
let mut permissions = file.metadata()?.permissions();
let mode = permissions.mode() | 0o111;
permissions.set_mode(mode);
file.set_permissions(permissions)?;
}
#[cfg(target_os = "macos")]
std::process::Command::new("xattr")
.arg("-d")
.arg("com.apple.quarantine")
.arg(&file_path)
.stderr(std::process::Stdio::null())
.stdout(std::process::Stdio::null())
.stdout(std::process::Stdio::null())
.spawn()?
.wait()?;
Ok(file_path)
}