Files
imeai-aKode/akode-rs/utils/cargo-bin/src/executable.rs
andrea.difonzo 7c1c6dfa8d Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
  nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 12:37:52 +01:00

63 lines
2.2 KiB
Rust

//! Creates executable test fixtures without exposing writable descriptors to sibling spawns.
//! On Linux, writes and copies finish in a separate process before the fixture can be launched.
use std::fs;
use std::io;
use std::path::Path;
#[cfg(target_os = "linux")]
use std::process::Command;
/// Writes a small Unix script fixture and makes it executable with mode 0o755.
#[cfg(unix)]
pub fn write_executable(path: &Path, script: &str) -> io::Result<()> {
use std::os::unix::fs::PermissionsExt;
#[cfg(target_os = "linux")]
{
// A sibling test can fork while a parent-owned file is open for writing.
// CLOEXEC does not release that inherited descriptor until the sibling execs.
let output = Command::new("/bin/sh")
.arg("-c")
.arg("printf '%s' \"$1\" > \"$2\"")
.arg("write-executable-fixture")
.arg(script)
.arg(path)
.output()?;
if !output.status.success() {
return Err(io::Error::other(format!(
"failed to write executable fixture {}: {}",
path.display(),
String::from_utf8_lossy(&output.stderr),
)));
}
}
#[cfg(not(target_os = "linux"))]
fs::write(path, script)?;
fs::set_permissions(path, fs::Permissions::from_mode(/*mode*/ 0o755))
}
/// Copies an executable fixture, preserving the source permissions like [`fs::copy`].
pub fn copy_executable(source: &Path, destination: &Path) -> io::Result<()> {
#[cfg(target_os = "linux")]
{
let output = Command::new("/bin/cp")
.arg("--")
.arg(source)
.arg(destination)
.output()?;
if !output.status.success() {
return Err(io::Error::other(format!(
"failed to copy executable fixture {} to {}: {}",
source.display(),
destination.display(),
String::from_utf8_lossy(&output.stderr),
)));
}
// Match fs::copy even when the test process has a restrictive umask.
fs::set_permissions(destination, fs::metadata(source)?.permissions())?;
}
#[cfg(not(target_os = "linux"))]
fs::copy(source, destination)?;
Ok(())
}