MCPcopy Create free account
hub / github.com/BitVM/BitVM / cleanup_cache_files

Function cleanup_cache_files

bridge/src/utils.rs:130–152  ·  view source on GitHub ↗
(prefix: &str, cache_location: &Path, max_cache_files: u32)

Source from the content-addressed store, hash-verified

128}
129
130pub fn cleanup_cache_files(prefix: &str, cache_location: &Path, max_cache_files: u32) {
131 let mut paths: Vec<PathBuf> = std::fs::read_dir(cache_location)
132 .unwrap()
133 .filter_map(Result::ok)
134 .filter(|entry| entry.file_name().to_str().unwrap_or("").starts_with(prefix))
135 .map(|entry| entry.path())
136 .collect();
137
138 paths.sort_by_key(|path| {
139 std::fs::metadata(path)
140 .and_then(|m| m.modified())
141 .unwrap_or_else(|_| std::time::SystemTime::now())
142 });
143
144 paths.reverse();
145 while paths.len() > max_cache_files as usize {
146 let oldest = paths.pop().unwrap();
147 std::fs::remove_file(&oldest)
148 .inspect_err(|e| eprintln!("Failed to delete the old cache file: {}", e))
149 .inspect(|_| println!("Old cache file deleted: {:?}", oldest))
150 .ok();
151 }
152}
153
154pub const DEFAULT_COMPRESSION_LEVEL: i32 = 5;
155

Callers 1

lock_scripts_bytesMethod · 0.85

Calls 1

lenMethod · 0.80

Tested by

no test coverage detected