cleanup_stale_locks

Function cleanup_stale_locks 

Source
pub async fn cleanup_stale_locks(
    cache_dir: &Path,
    ttl_seconds: u64,
) -> Result<usize>
Expand description

Cleans up stale lock files in the cache directory.

This function removes lock files that are older than the specified TTL (time-to-live) in seconds. Lock files can become stale if a process crashes without properly releasing its locks. This cleanup helps prevent lock file accumulation over time.

§Parameters

  • cache_dir - Root cache directory containing the .locks/ subdirectory
  • ttl_seconds - Maximum age in seconds for lock files (e.g., 3600 for 1 hour)

§Returns

Returns the number of stale lock files that were removed.

§Example

use agpm_cli::cache::lock::cleanup_stale_locks;
use std::path::PathBuf;

let cache_dir = PathBuf::from("/home/user/.agpm/cache");
// Clean up lock files older than 1 hour
let removed = cleanup_stale_locks(&cache_dir, 3600).await?;
println!("Removed {} stale lock files", removed);