{"record":{"id":"47831d489dc38055","repo":"BigPizzaV3/CodexPlusPlus","slug":"dreamskin-47831d","errorCode":null,"errorMessage":"DreamSkin 社区缓存无效","messagePattern":"DreamSkin 社区缓存无效","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/codex-plus-core/src/dream_skin_community.rs","lineNumber":398,"sourceCode":"    }\n}\n\nfn cache_catalog(state_dir: &Path, catalog: &DreamSkinCommunityCatalog) -> anyhow::Result<()> {\n    let path = state_dir.join(CACHE_FILE);\n    if let Some(parent) = path.parent() {\n        std::fs::create_dir_all(parent)?;\n    }\n    crate::settings::atomic_write(&path, &serde_json::to_vec(catalog)?)\n}\n\nfn read_cached_catalog(state_dir: &Path) -> anyhow::Result<DreamSkinCommunityCatalog> {\n    let path = state_dir.join(CACHE_FILE);\n    let metadata = std::fs::symlink_metadata(&path)?;\n    if !metadata.file_type().is_file()\n        || metadata.file_type().is_symlink()\n        || metadata.len() as usize > CATALOG_BYTES_LIMIT\n    {\n        bail!(\"DreamSkin 社区缓存无效\");\n    }\n    let mut catalog: DreamSkinCommunityCatalog = serde_json::from_slice(&std::fs::read(path)?)?;\n    let (items, skipped) = normalize_and_filter_catalog(catalog.items);\n    catalog.items = items;\n    catalog.total = catalog.items.len();\n    if skipped > 0 {\n        append_warning(\n            &mut catalog.warning,\n            format!(\"已跳过 {skipped} 个元数据无效的 DreamSkin 社区缓存主题。\"),\n        );\n    }\n    Ok(catalog)\n}\n\nfn append_warning(warning: &mut String, message: String) {\n    if !warning.is_empty() {\n        warning.push(' ');\n    }","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_community.rs#L380-L416","documentation":"read_cached_catalog validates the on-disk community catalog cache file before parsing: it must be a regular, non-symlink file no larger than CATALOG_BYTES_LIMIT. If the cache fails these checks (or symlink_metadata itself fails, or the JSON is invalid further down), the cache is considered unusable and the loader falls back to a network fetch.","triggerScenarios":"Calling load_community_catalog when the CACHE_FILE in state_dir is a symlink, a directory/special file, or larger than the catalog byte limit; or when symlink_metadata errors (missing path propagates a different error).","commonSituations":"State dir shared via symlinked folders; a corrupted/huge cache from a bad previous write; antivirus or sync tools replacing the file; an attacker-planted symlink.","solutions":["Delete the invalid cache file and let load_community_catalog refetch the catalog from the network.","Check the state_dir for symlink or sync-tool interference and use a plain directory.","Ensure no concurrent writer truncates/oversizes the cache; write atomically (temp file + rename)."],"exampleFix":"// before\nlet catalog = load_community_catalog(state_dir, false)?; // force-cache read errors surface\n// after\nlet catalog = load_community_catalog(state_dir, true)?; // force refresh, ignore/rebuild cache","handlingStrategy":"fallback","validationCode":"// Rust\nlet md = std::fs::symlink_metadata(&cache_path);\nlet cache_ok = md.as_ref().map(|m| m.is_file() && m.len() <= CATALOG_LIMIT).unwrap_or(false);","typeGuard":null,"tryCatchPattern":"// Rust\nlet catalog = match load_community_catalog(state_dir, false).await {\n    Ok(c) => c,\n    Err(_) => load_community_catalog(state_dir, true).await?, // force network refresh, rebuilding cache\n};","preventionTips":["Treat the cache as disposable and fall back to network on any read error","Write the cache atomically (temp + rename)","Avoid symlinked or cloud-synced state directories"],"tags":["cache","validation","file"],"backgroundTag":"file-read-failed","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}