MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / enter_dir

Method enter_dir

crates/cache/src/worker.rs:540–728  ·  view source on GitHub ↗
(
            vec: &mut Vec<CacheEntry>,
            dir_path: &Path,
            level: u8,
            cache_config: &CacheConfig,
        )

Source from the content-addressed store, hash-verified

538 // Be fault tolerant: list as much as you can, and ignore the rest
539 fn list_cache_contents(&self) -> Vec<CacheEntry> {
540 fn enter_dir(
541 vec: &mut Vec<CacheEntry>,
542 dir_path: &Path,
543 level: u8,
544 cache_config: &CacheConfig,
545 ) {
546 macro_rules! add_unrecognized {
547 (file: $path:expr) => {
548 add_unrecognized!(false, $path)
549 };
550 (dir: $path:expr) => {
551 add_unrecognized!(true, $path)
552 };
553 ($is_dir:expr, $path:expr) => {
554 vec.push(CacheEntry::Unrecognized {
555 path: $path.to_path_buf(),
556 is_dir: $is_dir,
557 })
558 };
559 }
560 macro_rules! add_unrecognized_and {
561 ([ $( $ty:ident: $path:expr ),* ], $cont:stmt) => {{
562 $( add_unrecognized!($ty: $path); )*
563 $cont
564 }};
565 }
566
567 macro_rules! unwrap_or {
568 ($result:expr, $cont:stmt, $err_msg:expr) => {
569 unwrap_or!($result, $cont, $err_msg, dir_path)
570 };
571 ($result:expr, $cont:stmt, $err_msg:expr, $path:expr) => {
572 unwrap_or_warn!(
573 $result,
574 $cont,
575 format!("{}, level: {}", $err_msg, level),
576 $path
577 )
578 };
579 }
580
581 // If we fail to list a directory, something bad is happening anyway
582 // (something touches our cache or we have disk failure)
583 // Try to delete it, so we can stay within soft limits of the cache size.
584 // This comment applies later in this function, too.
585 let it = unwrap_or!(
586 fs::read_dir(dir_path),
587 add_unrecognized_and!([dir: dir_path], return),
588 "Failed to list cache directory, deleting it"
589 );
590
591 let mut cache_files = HashMap::new();
592 for entry in it {
593 // read_dir() returns an iterator over results - in case some of them are errors
594 // we don't know their names, so we can't delete them. We don't want to delete
595 // the whole directory with good entries too, so we just ignore the erroneous entries.
596 let entry = unwrap_or!(
597 entry,

Callers

nothing calls this directly

Calls 11

is_fs_lock_expiredFunction · 0.85
is_dirMethod · 0.80
newFunction · 0.50
pathMethod · 0.45
is_someMethod · 0.45
insertMethod · 0.45
iterMethod · 0.45
mapMethod · 0.45
getMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected