Writes the `node` wrapper script and returns its folder. The folder is a fresh temp dir with a random name, created exclusively and writable only by us: a shared, predictable path could be pre-created by another user, who could then replace the script that ends up first on `PATH`. It is kept after the process exits, since benchmarks execute the wrapper until then. A process installs at most once
()
| 39 | /// race with concurrent `fork`+`exec` calls: the child inherits the writable |
| 40 | /// descriptor and then fails to execute the script with `ETXTBSY`. |
| 41 | fn install_wrapper() -> std::io::Result<PathBuf> { |
| 42 | let mut installed = INSTALLED_DIR.lock().unwrap_or_else(|e| e.into_inner()); |
| 43 | if let Some(dir) = installed.as_ref() { |
| 44 | return Ok(dir.clone()); |
| 45 | } |
| 46 | |
| 47 | let dir = tempfile::Builder::new() |
| 48 | .prefix(WRAPPER_DIR_PREFIX) |
| 49 | .tempdir()? |
| 50 | .keep(); |
| 51 | let script = dir.join(WRAPPER_FILE_NAME); |
| 52 | std::fs::write(&script, NODE_WRAPPER_SCRIPT)?; |
| 53 | std::fs::set_permissions(&script, std::fs::Permissions::from_mode(EXECUTABLE_MODE))?; |
| 54 | |
| 55 | *installed = Some(dir.clone()); |
| 56 | Ok(dir) |
| 57 | } |
| 58 | |
| 59 | /// Installs the `node` wrapper and returns `path` with its folder prepended. |
| 60 | pub(super) fn path_with_node_wrapper(path: &OsStr) -> anyhow::Result<OsString> { |
no test coverage detected