docs: tambah doc comment, logging, dan inline comments di semua 255 file

Meliputi:
- File-level //! doc comment: tujuan file, alur kerja, komponen utama
- Function-level /// doc comment: apa, parameter, return, flow, edge cases
- Struct/enum/trait /// doc comment: peran, field docs
- Tracing logging (tracing::info!/debug!/trace!/warn!/error!) di setiap fungsi
- Inline comments untuk variable dan branching logic penting
- Seluruh 8 crates di workspace: zesdex-backend, zesdex-cms, zesdex-entities,
  zesdex-iam, zesdex-infra, zesdex-ipc, zesdex-middleware, zesdex-utils
- Build: 0 errors, 242/242 tests passed
This commit is contained in:
asepharyana
2026-07-19 17:05:47 +07:00
parent 6680795ce7
commit 5aaedbf787
255 changed files with 5666 additions and 743 deletions
@@ -6,10 +6,23 @@
//! check to guard against PID reuse. This repository is stateless (no
//! `Drop`-based auto-release) — callers that need panic-safety should wrap
//! acquisition in their own RAII guard (see `zesdex-backend`'s
//! `main.rs::SessionLockGuard`, added in a later task of this plan).
//! `main.rs::SessionLockGuard`).
//!
//! # Flow
//!
//! 1. **`try_lock`** — attempt `O_CREAT|O_EXCL` open on `<session_dir>/.lock`;
//! if it already exists, check PID liveness; if stale, overwrite atomically.
//! 2. **`unlock`** — remove the `.lock` file.
//! 3. **`is_alive`** — `libc::kill(pid, 0)` + `/proc/<pid>/exe` identity check.
//!
//! # Components
//!
//! - `FileSystemSessionLockRepository` — stateless singleton implementing
//! `SessionLockRepository`
use std::fs;
use std::io::Write;
use std::path::Path;
use tracing;
use crate::domain::repository::SessionLockRepository;
@@ -38,17 +51,22 @@ impl SessionLockRepository for FileSystemSessionLockRepository {
Ok(mut file) => {
write!(file, "{pid}")?;
file.sync_all()?;
tracing::debug!(path = %path.display(), pid, "session lock acquired");
return Ok(true);
}
Err(ref e) if e.kind() == std::io::ErrorKind::AlreadyExists => {}
Err(ref e) if e.kind() == std::io::ErrorKind::AlreadyExists => {
tracing::debug!(path = %path.display(), "lock file exists, checking staleness");
}
Err(e) => return Err(e.into()),
}
let content = fs::read_to_string(&path).unwrap_or_default();
if let Ok(existing_pid) = content.trim().parse::<u32>() {
if self.is_alive(existing_pid) {
tracing::warn!(existing_pid, path = %path.display(), "session lock held by live process");
return Ok(false);
}
tracing::debug!(existing_pid, "stale lock detected, overwriting");
}
let tmp = path.with_extension("lock.tmp");