fn cleanup_run_logs(log_dir: &Path, max_files: usize) -> Result<(), Error>Expand description
Removes old log files to maintain the configured retention limit.
This function scans the log directory for files matching the pattern
cadmus-*.json and deletes the oldest files if the count exceeds max_files.
Note: this relies on the run ID being a UUID v7 (time-ordered). Filenames are
cadmus-<run_id>.json where <run_id> is generated with Uuid::now_v7(),
so lexicographic sorting of the filenames corresponds to chronological order.
Sorting by file name therefore yields oldest-first ordering for removal.
§Arguments
log_dir- Path to the directory containing log filesmax_files- Maximum number of log files to retain (0 = keep all)
§Returns
Returns Ok(()) on success.
§Errors
Returns an error if:
- The log directory cannot be read
- Individual directory entries cannot be read
- Old log files cannot be deleted