Add a route to upload update to the platform
This commit is contained in:
24
central_backend/src/ota/ota_manager.rs
Normal file
24
central_backend/src/ota/ota_manager.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
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(())
|
||||
}
|
||||
Reference in New Issue
Block a user