Get the list of OTA updates for a given platform

This commit is contained in:
2024-10-05 19:35:23 +02:00
parent 2feb3f6490
commit d38040cb98
5 changed files with 48 additions and 8 deletions

View File

@ -1,6 +1,8 @@
use crate::app_config::AppConfig;
use crate::ota::ota_update::OTAPlatform;
use crate::ota::ota_update::{OTAPlatform, OTAUpdate};
use crate::utils::files_utils;
use std::os::unix::fs::MetadataExt;
use std::str::FromStr;
/// Check out whether a given update exists or not
pub fn update_exists(platform: OTAPlatform, version: &semver::Version) -> anyhow::Result<bool> {
@ -22,3 +24,22 @@ pub fn save_update(
Ok(())
}
/// Get the list of OTA software updates for a platform
pub fn get_ota_updates_for_platform(platform: OTAPlatform) -> anyhow::Result<Vec<OTAUpdate>> {
let ota_path = AppConfig::get().ota_platform_dir(platform);
let mut out = Vec::new();
for e in std::fs::read_dir(ota_path)? {
let e = e?;
out.push(OTAUpdate {
platform,
version: semver::Version::from_str(e.file_name().to_str().unwrap_or("bad"))?,
file_size: e.metadata()?.size(),
});
}
Ok(out)
}

View File

@ -16,7 +16,7 @@ impl Display for OTAPlatform {
/// Single OTA update information
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct OTAUpdate {
platform: OTAPlatform,
version: semver::Version,
file_size: usize,
pub platform: OTAPlatform,
pub version: semver::Version,
pub file_size: u64,
}