Function atomic_file::open_file

source ·
pub async fn open_file(
    filepath: &PathBuf,
    expected_identifier: &str,
    latest_version: u8,
    upgrades: &Vec<Upgrade>
) -> Result<AtomicFile, Error>
Expand description

open_file will open an atomic file, using the backup of the file if the checksum fails. If the file does not yet exist and no backup file exists, a blank file will be opened. Data will not be written to the blank file until

If the file does not yet exist, a new file will be created and the file will be empty. The file will automatically be assigned the latest_version. If the file exists but has an outdated version, the upgrades will be used to convert the file to the latest version.

An error will be returned if the file does exist and has the wrong identifier, or if the file has a version that is higher than ‘latest_version’, or if the upgrades do not provide a valid path from the current version of the file to the latest version, or if both the file and the backup file are corrupt.