Skip to main content

Module fsutil

Module fsutil 

Source
Expand description

Filesystem helpers for temp directories, atomic writes, path normalization, and safeguard dumps.

Responsibilities:

  • Create and clean Ralph temp directories.
  • Write files atomically and sync parent directories best-effort.
  • Persist safeguard dumps for troubleshooting output.
  • Redact sensitive data in safeguard dumps by default (secrets, API keys, tokens).
  • Expand tilde (~) to the user’s home directory for Unix-style paths.

Not handled here:

  • Directory locks or lock ownership metadata (see crate::lock).
  • Cross-device file moves or distributed filesystem semantics.
  • Retry/backoff behavior beyond the current best-effort operations.
  • Redaction logic itself (see crate::redaction).

Invariants/assumptions:

  • Callers provide valid paths; write_atomic requires a parent directory.
  • Temp cleanup is best-effort and may skip entries on IO errors.
  • safeguard_text_dump requires explicit opt-in (env var or debug mode) to write raw content.
  • safeguard_text_dump_redacted is the default and safe choice for error dumps.
  • expand_tilde only handles leading ~ or ~/..., not ~user/... or nested tildes.

Re-exports§

pub use crate::constants::paths::RALPH_TEMP_PREFIX;

Functions§

cleanup_default_temp_dirs
cleanup_stale_temp_dirs
cleanup_stale_temp_entries
create_ralph_temp_dir
create_ralph_temp_file
Creates a NamedTempFile in the ralph temp directory with the ralph_ prefix. This ensures the file will be caught by cleanup_default_temp_dirs().
expand_tilde
Expands a leading ~ to the user’s home directory ($HOME) for Unix-style paths.
ralph_temp_root
safeguard_text_dump
Writes a safeguard dump with raw (non-redacted) content.
safeguard_text_dump_redacted
Writes a safeguard dump with redaction applied to sensitive content.
write_atomic