Skip to main content

load_from_disk_or_default

Function load_from_disk_or_default 

Source
pub fn load_from_disk_or_default(path: &Path) -> OfficialIndex
Expand description

What: Load an official package index from disk, tolerating missing or corrupt files.

Inputs:

  • path: File path to read the JSON index from.

Output:

  • The deserialized index, or an empty OfficialIndex when the file is missing, unreadable, or not valid index JSON.

Details:

  • Convenience wrapper over load_from_disk for resilient startup paths (Pacsea’s original semantics): a corrupt cache should trigger a fresh fetch, not a startup error. The failure reason is logged at debug level.

§Example

use arch_toolkit::index::{fetch_official_index, load_from_disk_or_default};
use std::path::Path;

let mut index = load_from_disk_or_default(Path::new("official_index.json"));
if index.pkgs.is_empty() {
    index = fetch_official_index()?;
}