25 lines
689 B
Rust
25 lines
689 B
Rust
|
use crate::app_config::AppConfig;
|
||
|
use crate::ota::ota_update::OTAPlatform;
|
||
|
use crate::utils::files_utils;
|
||
|
|
||
|
/// Check out whether a given update exists or not
|
||
|
pub fn update_exists(platform: OTAPlatform, version: &semver::Version) -> anyhow::Result<bool> {
|
||
|
Ok(AppConfig::get()
|
||
|
.path_ota_update(platform, version)
|
||
|
.is_file())
|
||
|
}
|
||
|
|
||
|
/// Save a new firmware update
|
||
|
pub fn save_update(
|
||
|
platform: OTAPlatform,
|
||
|
version: &semver::Version,
|
||
|
update: &[u8],
|
||
|
) -> anyhow::Result<()> {
|
||
|
let path = AppConfig::get().path_ota_update(platform, version);
|
||
|
files_utils::create_directory_if_missing(path.parent().unwrap())?;
|
||
|
|
||
|
std::fs::write(path, update)?;
|
||
|
|
||
|
Ok(())
|
||
|
}
|