Skip to content

Commit

Permalink
updatehub: Add support for RawDelta objects
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathas-Conceicao <jonathas.conceicao@ossystems.com.br>
  • Loading branch information
Jonathas-Conceicao committed Aug 25, 2021
1 parent c15bee1 commit b01f9ff
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
7 changes: 5 additions & 2 deletions updatehub/src/object/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use super::Result;
use crate::utils;
use openssl::sha::Sha256;
use pkg_schema::{
objects::{Copy, Flash, Imxkobs, Mender, Raw, Tarball, Test, Ubifs, UbootEnv, Zephyr},
objects::{
Copy, Flash, Imxkobs, Mender, Raw, RawDelta, Tarball, Test, Ubifs, UbootEnv, Zephyr,
},
Object,
};
use std::{
Expand All @@ -23,6 +25,7 @@ pub(crate) enum Status {
Ready,
}

impl_remote_object_info!(RawDelta);
impl_compressed_object_info!(Copy);
impl_compressed_object_info!(Raw);
impl_compressed_object_info!(Ubifs);
Expand All @@ -35,7 +38,7 @@ impl_object_info!(UbootEnv);
impl_object_info!(Zephyr);

impl_object_for_object_types!(
Copy, Flash, Imxkobs, Mender, Tarball, Ubifs, Raw, Test, UbootEnv, Zephyr
RawDelta, Copy, Flash, Imxkobs, Mender, Tarball, Ubifs, Raw, Test, UbootEnv, Zephyr
);

pub(crate) trait Info {
Expand Down
1 change: 1 addition & 0 deletions updatehub/src/object/installer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod flash;
mod imxkobs;
mod mender;
mod raw;
mod raw_delta;
mod tarball;
mod test;
mod ubifs;
Expand Down
68 changes: 68 additions & 0 deletions updatehub/src/object/installer/raw_delta.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (C) 2021 O.S. Systems Sofware LTDA
//
// SPDX-License-Identifier: Apache-2.0

use super::{Context, Error, Result};
use crate::{
object::Installer,
utils::{self, definitions::TargetTypeExt, delta},
};

use pkg_schema::{definitions, objects};
use slog_scope::info;

#[async_trait::async_trait(?Send)]
impl Installer for objects::RawDelta {
async fn check_requirements(&self, context: &Context) -> Result<()> {
info!("'raw-delta' handle checking requirements");

if let definitions::TargetType::Device(dev) = self.target.valid()? {
let seed = get_seed_path(self, context);
let required_size = delta::get_required_size(&seed, dev).await?;
utils::fs::ensure_disk_space(&dev, required_size)?;
return Ok(());
}
Err(Error::InvalidTargetType(self.target.clone()))
}

async fn install(&self, context: &Context) -> Result<()> {
info!("'raw-delta' handler Install {} ({})", self.filename, self.sha256sum);

let target = self.target.get_target()?;
// Clone's chunk size is used from archives definition,
// so we can ignore this parameter here
let _ = self.chunk_size.0;
let source = get_seed_path(self, context);

delta::clone(&source, &target, self.seek).await?;

Ok(())
}
}

fn get_seed_path(obj: &objects::RawDelta, context: &Context) -> String {
if context.offline_update {
format!("{:?}", context.download_dir.join(&obj.sha256sum))
} else {
format!("{}/{}", context.base_url, &obj.sha256sum)
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::object::installer::tests::create_echo_bins;
use pretty_assertions::assert_eq;
use std::env;

fn fake_raw_delta_obj() -> objects::RawDelta {
objects::RawDelta {
filename: "etc/passwd".to_string(),
sha256sum: "cfe2be1c64b03875008".to_string(),
target: definitions::TargetType::Device(std::path::PathBuf::from("/dev/sda1")),
chunk_size: definitions::ChunkSize::default(),
seek: 0,
size: 1024,
}
}
}
1 change: 1 addition & 0 deletions updatehub/src/object/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ macro_rules! for_any_object {
Object::Imxkobs($alias) => $code,
Object::Mender($alias) => $code,
Object::Raw($alias) => $code,
Object::RawDelta($alias) => $code,
Object::Tarball($alias) => $code,
Object::Test($alias) => $code,
Object::Ubifs($alias) => $code,
Expand Down
2 changes: 0 additions & 2 deletions updatehub/src/utils/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//
// SPDX-License-Identifier: Apache-2.0

#![allow(dead_code)]

use super::Result;
use bitar::{Archive, ChunkIndex, CloneOutput, ReaderRemote};
use futures_util::{StreamExt, TryStreamExt};
Expand Down

0 comments on commit b01f9ff

Please sign in to comment.