MCPcopy Index your code
hub / github.com/Firstyear/opensuse-proxy-cache / new

Method new

arc-disk-cache/src/lib.rs:279–481  ·  view source on GitHub ↗
(capacity: usize, content_dir: P, durable_fs: bool)

Source from the content-addressed store, hash-verified

277 D: Serialize + DeserializeOwned + Clone + Debug + Sync + Send + 'static,
278{
279 pub fn new<P>(capacity: usize, content_dir: P, durable_fs: bool) -> io::Result<Self>
280 where
281 P: AsRef<Path>,
282 {
283 let content_dir: &Path = content_dir.as_ref();
284
285 info!("capacity: {} content_dir: {:?}", capacity, content_dir);
286
287 let cache = Arc::new(
288 ARCacheBuilder::new()
289 .set_size(capacity, 0)
290 .set_watermark(0)
291 .set_reader_quiesce(false)
292 .build()
293 .ok_or_else(|| {
294 io::Error::new(
295 io::ErrorKind::Other,
296 "Failed to build Arc Disk Cache - Invalid Parameters",
297 )
298 })?,
299 );
300
301 let running = Arc::new(AtomicBool::new(true));
302 // Clean up the legacy content structure.
303 let entries = std::fs::read_dir(content_dir)?
304 .filter_map(|dir_ent| dir_ent.ok().map(|d| d.path()))
305 .filter(|dir_ent| !dir_ent.is_dir())
306 .collect::<Vec<_>>();
307
308 let garbage_path = content_dir.join("garbage");
309
310 if !garbage_path.exists() {
311 let _ = fs::create_dir(&garbage_path);
312 }
313
314 let temp_path = content_dir.join("tmp");
315
316 if !temp_path.exists() {
317 let _ = fs::create_dir(&temp_path);
318 }
319
320 debug!("Start cleanup");
321
322 for dir_ent in entries {
323 if let Some(fname) = dir_ent.file_name() {
324 let dir_ent_gbg = garbage_path.join(fname);
325 info!("{:?}", dir_ent_gbg);
326 if !dir_ent_gbg.exists() {
327 fs::rename(dir_ent, dir_ent_gbg).inspect_err(|err| error!(?err))?
328 } else {
329 warn!("Unable to cleanup {:?}", dir_ent_gbg);
330 }
331 }
332 }
333
334 debug!("start new content dirs");
335
336 // Make a map for the u8 -> hex str.

Callers

nothing calls this directly

Calls 3

crc32c_lenFunction · 0.85
pathMethod · 0.80
removeMethod · 0.80

Tested by

no test coverage detected