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>
This commit is contained in:
89
akode-rs/file-system/src/local_logs.rs
Normal file
89
akode-rs/file-system/src/local_logs.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
//! Defers diagnostic directory creation and the Unix cleanup lock until initialization.
|
||||
//! The caller selects the path. This module does not search for storage.
|
||||
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::OnceCell;
|
||||
|
||||
/// A diagnostic directory whose clones share deferred setup and a Unix cleanup lock.
|
||||
#[derive(Clone, Debug)]
|
||||
#[must_use = "keep the guard until all log connections close"]
|
||||
pub struct LocalLogsDir {
|
||||
path: PathBuf,
|
||||
initialized: Arc<OnceCell<LocalLogsDirLock>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct LocalLogsDirLock {
|
||||
#[cfg(unix)]
|
||||
_cleanup_lock: std::fs::File,
|
||||
}
|
||||
|
||||
impl LocalLogsDir {
|
||||
/// Select a directory without accessing the filesystem.
|
||||
pub fn new(path: PathBuf) -> Self {
|
||||
Self {
|
||||
path,
|
||||
initialized: Arc::new(OnceCell::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create the directory and acquire its cleanup lock once. Failed attempts remain retryable.
|
||||
/// Keep a clone alive until all log connections close.
|
||||
/// On Unix, newly created directories start with mode 0700. Existing permissions
|
||||
/// are preserved, including on user-created directories or after the user changes
|
||||
/// the mode. We do not enforce or restore private permissions on later calls.
|
||||
pub async fn initialize(&self) -> io::Result<()> {
|
||||
let _ = self
|
||||
.initialized
|
||||
.get_or_try_init(|| async {
|
||||
let path = self.path.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let mut builder = std::fs::DirBuilder::new();
|
||||
builder.recursive(true);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::DirBuilderExt;
|
||||
|
||||
// Set private permissions only at creation; preserve existing permissions.
|
||||
builder.mode(0o700);
|
||||
}
|
||||
builder.create(&path)?;
|
||||
// Protect temporary log directories from cleanup while connections use them.
|
||||
#[cfg(unix)]
|
||||
let directory = {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
|
||||
let directory = std::fs::File::open(&path)?;
|
||||
directory.try_lock_shared()?;
|
||||
let locked = directory.metadata()?;
|
||||
let current = std::fs::metadata(&path)?;
|
||||
if !locked.is_dir()
|
||||
|| (current.dev(), current.ino()) != (locked.dev(), locked.ino())
|
||||
{
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
"log directory changed during initialization",
|
||||
));
|
||||
}
|
||||
directory
|
||||
};
|
||||
|
||||
Ok::<_, io::Error>(LocalLogsDirLock {
|
||||
#[cfg(unix)]
|
||||
_cleanup_lock: directory,
|
||||
})
|
||||
})
|
||||
.await
|
||||
.map_err(io::Error::other)?
|
||||
})
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn path(&self) -> &Path {
|
||||
&self.path
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user